mirror of
https://github.com/maaslalani/gambit.git
synced 2024-12-26 20:54:07 +02:00
styling
This commit is contained in:
parent
35192ca66a
commit
7a2151020f
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
9
style/style.go
Normal 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"))
|
||||
)
|
Loading…
Reference in New Issue
Block a user