Skip to content

Commit

Permalink
feat: chess table with table renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Oct 4, 2023
1 parent fb63563 commit 2687d82
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/table/chess/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"fmt"
"os"
"strings"

"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
)

func main() {
re := lipgloss.NewRenderer(os.Stdout)
labelStyle := re.NewStyle().Foreground(lipgloss.Color("241"))

board := [][]any{
{"β™œ", "β™ž", "♝", "β™›", "β™š", "♝", "β™ž", "β™œ"},
{"β™Ÿ", "β™Ÿ", "β™Ÿ", "β™Ÿ", "β™Ÿ", "β™Ÿ", "β™Ÿ", "β™Ÿ"},
{" ", " ", " ", " ", " ", " ", " ", " "},
{" ", " ", " ", " ", " ", " ", " ", " "},
{" ", " ", " ", " ", " ", " ", " ", " "},
{" ", " ", " ", " ", " ", " ", " ", " "},
{"β™™", "β™™", "β™™", "β™™", "β™™", "β™™", "β™™", "β™™"},
{"β™–", "β™˜", "β™—", "β™•", "β™”", "β™—", "β™˜", "β™–"},
}

t := table.New().
Border(lipgloss.NormalBorder()).
BorderRow(true).
BorderColumn(true).
Rows(board...).
StyleFunc(func(row, col int) lipgloss.Style {
return lipgloss.NewStyle().Padding(0, 1)
})

ranks := labelStyle.Render(strings.Join([]string{" A", "B", "C", "D", "E", "F", "G", "H "}, " "))
files := labelStyle.Render(strings.Join([]string{" 1", "2", "3", "4", "5", "6", "7", "8 "}, "\n\n "))

fmt.Println(lipgloss.JoinVertical(lipgloss.Right, lipgloss.JoinHorizontal(lipgloss.Center, files, t.Render()), ranks) + "\n")
}

0 comments on commit 2687d82

Please sign in to comment.