mirror of
https://github.com/brianstrauch/solitaire-tui.git
synced 2024-12-26 21:58:44 +01:00
clear screen, fix colors
This commit is contained in:
parent
944d9def9a
commit
32847475aa
2 changed files with 11 additions and 20 deletions
|
@ -2,6 +2,7 @@ package solitaire
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/brianstrauch/solitaire-tui/pkg"
|
"github.com/brianstrauch/solitaire-tui/pkg"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
|
@ -36,10 +37,7 @@ var deckTypes = []deckType{
|
||||||
type Solitaire struct {
|
type Solitaire struct {
|
||||||
decks []*pkg.Deck
|
decks []*pkg.Deck
|
||||||
selected *index
|
selected *index
|
||||||
|
|
||||||
mouse tea.MouseMsg
|
mouse tea.MouseMsg
|
||||||
windowHeight int
|
|
||||||
maxHeight int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type index struct {
|
type index struct {
|
||||||
|
@ -73,7 +71,7 @@ func New() *Solitaire {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Solitaire) Init() tea.Cmd {
|
func (s *Solitaire) Init() tea.Cmd {
|
||||||
return nil
|
return tea.ClearScreen
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Solitaire) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (s *Solitaire) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
@ -83,8 +81,6 @@ func (s *Solitaire) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
case "q", "ctrl+c", "esc":
|
case "q", "ctrl+c", "esc":
|
||||||
return s, tea.Quit
|
return s, tea.Quit
|
||||||
}
|
}
|
||||||
case tea.WindowSizeMsg:
|
|
||||||
s.windowHeight = msg.Height
|
|
||||||
case tea.MouseMsg:
|
case tea.MouseMsg:
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
case tea.MouseLeft:
|
case tea.MouseLeft:
|
||||||
|
@ -93,12 +89,7 @@ func (s *Solitaire) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
}
|
}
|
||||||
case tea.MouseRelease:
|
case tea.MouseRelease:
|
||||||
if s.mouse.Type == tea.MouseLeft && msg.X == s.mouse.X && msg.Y == s.mouse.Y {
|
if s.mouse.Type == tea.MouseLeft && msg.X == s.mouse.X && msg.Y == s.mouse.Y {
|
||||||
height := lipgloss.Height(s.View())
|
s.click(msg.X, msg.Y)
|
||||||
if height > s.maxHeight {
|
|
||||||
s.maxHeight = height
|
|
||||||
}
|
|
||||||
y := msg.Y - (s.windowHeight - s.maxHeight)
|
|
||||||
s.click(msg.X, y)
|
|
||||||
}
|
}
|
||||||
s.mouse = msg
|
s.mouse = msg
|
||||||
}
|
}
|
||||||
|
|
14
pkg/card.go
14
pkg/card.go
|
@ -33,14 +33,14 @@ func NewCard(value, suit int) *Card {
|
||||||
func (c *Card) View() string {
|
func (c *Card) View() string {
|
||||||
color := lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"}
|
color := lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"}
|
||||||
|
|
||||||
if c.IsSelected {
|
|
||||||
color = lipgloss.AdaptiveColor{Light: "#FFFF00", Dark: "#FFFF00"}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !c.IsVisible {
|
if !c.IsVisible {
|
||||||
return viewCard("╱", "", color)
|
return viewCard("╱", "", color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.IsSelected {
|
||||||
|
color = lipgloss.AdaptiveColor{Light: "#FFFF00", Dark: "#00FFFF"}
|
||||||
|
}
|
||||||
|
|
||||||
style := lipgloss.NewStyle().Foreground(c.Color())
|
style := lipgloss.NewStyle().Foreground(c.Color())
|
||||||
return viewCard(" ", style.Render(c.String()), color)
|
return viewCard(" ", style.Render(c.String()), color)
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,10 @@ func (c *Card) Flip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Card) Color() lipgloss.AdaptiveColor {
|
func (c *Card) Color() lipgloss.AdaptiveColor {
|
||||||
if c.Suit == 1 || c.Suit == 2 {
|
if c.Suit == 0 || c.Suit == 3 {
|
||||||
return lipgloss.AdaptiveColor{Light: "#FF0000", Dark: "#FF0000"}
|
return lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"}
|
||||||
} else {
|
} else {
|
||||||
return lipgloss.AdaptiveColor{Light: "#000000", Dark: "#888888"}
|
return lipgloss.AdaptiveColor{Light: "#FF0000", Dark: "#FF0000"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue