clear screen, fix colors

This commit is contained in:
Brian Strauch 2023-01-30 23:11:20 -08:00
parent 944d9def9a
commit 32847475aa
2 changed files with 11 additions and 20 deletions

View file

@ -2,6 +2,7 @@ package solitaire
import (
"github.com/brianstrauch/solitaire-tui/pkg"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
@ -36,10 +37,7 @@ var deckTypes = []deckType{
type Solitaire struct {
decks []*pkg.Deck
selected *index
mouse tea.MouseMsg
windowHeight int
maxHeight int
}
type index struct {
@ -73,7 +71,7 @@ func New() *Solitaire {
}
func (s *Solitaire) Init() tea.Cmd {
return nil
return tea.ClearScreen
}
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":
return s, tea.Quit
}
case tea.WindowSizeMsg:
s.windowHeight = msg.Height
case tea.MouseMsg:
switch msg.Type {
case tea.MouseLeft:
@ -93,12 +89,7 @@ func (s *Solitaire) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case tea.MouseRelease:
if s.mouse.Type == tea.MouseLeft && msg.X == s.mouse.X && msg.Y == s.mouse.Y {
height := lipgloss.Height(s.View())
if height > s.maxHeight {
s.maxHeight = height
}
y := msg.Y - (s.windowHeight - s.maxHeight)
s.click(msg.X, y)
s.click(msg.X, msg.Y)
}
s.mouse = msg
}

View file

@ -33,14 +33,14 @@ func NewCard(value, suit int) *Card {
func (c *Card) View() string {
color := lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"}
if c.IsSelected {
color = lipgloss.AdaptiveColor{Light: "#FFFF00", Dark: "#FFFF00"}
}
if !c.IsVisible {
return viewCard("", "", color)
}
if c.IsSelected {
color = lipgloss.AdaptiveColor{Light: "#FFFF00", Dark: "#00FFFF"}
}
style := lipgloss.NewStyle().Foreground(c.Color())
return viewCard(" ", style.Render(c.String()), color)
}
@ -50,10 +50,10 @@ func (c *Card) Flip() {
}
func (c *Card) Color() lipgloss.AdaptiveColor {
if c.Suit == 1 || c.Suit == 2 {
return lipgloss.AdaptiveColor{Light: "#FF0000", Dark: "#FF0000"}
if c.Suit == 0 || c.Suit == 3 {
return lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"}
} else {
return lipgloss.AdaptiveColor{Light: "#000000", Dark: "#888888"}
return lipgloss.AdaptiveColor{Light: "#FF0000", Dark: "#FF0000"}
}
}