From 7a2151020f69d7619a65b58666f70cf5291e1039 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Wed, 22 Dec 2021 14:26:59 -0500 Subject: [PATCH] styling --- board/display.go | 5 +++-- game/game.go | 4 ++++ piece/piece.go | 8 +++++++- style/style.go | 9 +++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 style/style.go diff --git a/board/display.go b/board/display.go index 97f5fab..b4371c8 100644 --- a/board/display.go +++ b/board/display.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/maaslalani/gambit/position" + "github.com/maaslalani/gambit/style" ) const ( @@ -47,7 +48,7 @@ func (b Board) String() string { for c, cell := range b.Grid[row] { // Rank labels if isFirstColumn(c) { - s += " " + position.RowToRank(row) + " " + s += " " + style.Faint.Render(position.RowToRank(row)) + " " } s += vertical + " " + cell.String() + " " @@ -62,7 +63,7 @@ func (b Board) String() string { } else { s += buildRow(border[bottom]) + "\n" // File labels - s += " " + strings.Join(files, " ") + "\n" + s += " " + style.Faint.Render(strings.Join(files, " ")) + "\n" } } diff --git a/game/game.go b/game/game.go index b86c623..e080854 100644 --- a/game/game.go +++ b/game/game.go @@ -37,6 +37,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { col := (msg.X - marginLeft) / cellWidth row := (msg.Y - marginTop) / cellHeight + if col < 0 || col > 7 || row < 0 || row > 7 { + return m, nil + } + if !m.board.Reversed { row = 7 - row } diff --git a/piece/piece.go b/piece/piece.go index 9b2b2ca..00527f5 100644 --- a/piece/piece.go +++ b/piece/piece.go @@ -1,5 +1,7 @@ package piece +import "github.com/maaslalani/gambit/style" + type Piece struct { Type Type Color Color @@ -10,7 +12,11 @@ func Empty() Piece { } func (p Piece) String() string { - return Display[p.Type] + if p.Color == White { + return style.White.Render(Display[p.Type]) + } else { + return style.Black.Render(Display[p.Type]) + } } var ( diff --git a/style/style.go b/style/style.go new file mode 100644 index 0000000..76f9e39 --- /dev/null +++ b/style/style.go @@ -0,0 +1,9 @@ +package style + +import "github.com/charmbracelet/lipgloss" + +var ( + Faint = lipgloss.NewStyle().Foreground(lipgloss.Color("8")) + White = lipgloss.NewStyle().Foreground(lipgloss.Color("7")) + Black = lipgloss.NewStyle().Foreground(lipgloss.Color("4")) +)