1
0
mirror of https://github.com/maaslalani/gambit.git synced 2024-12-26 20:54:07 +02:00
This commit is contained in:
Maas Lalani 2021-12-22 14:26:59 -05:00
parent 35192ca66a
commit 7a2151020f
No known key found for this signature in database
GPG Key ID: 5A6ED5CBF1A0A000
4 changed files with 23 additions and 3 deletions

View File

@ -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"
}
}

View File

@ -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
}

View File

@ -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 (

9
style/style.go Normal file
View File

@ -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"))
)