Skip to content

Commit

Permalink
fix: examples to Data interface
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Oct 4, 2023
1 parent ca7a112 commit 4f6f552
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions examples/table/chess/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
re := lipgloss.NewRenderer(os.Stdout)
labelStyle := re.NewStyle().Foreground(lipgloss.Color("241"))

board := [][]any{
board := [][]string{
{"♜", "♞", "♝", "♛", "♚", "♝", "♞", "♜"},
{"♟", "♟", "♟", "♟", "♟", "♟", "♟", "♟"},
{" ", " ", " ", " ", " ", " ", " ", " "},
Expand All @@ -28,7 +28,7 @@ func main() {
Border(lipgloss.NormalBorder()).
BorderRow(true).
BorderColumn(true).
Rows(board...).
Rows(table.Rows(board...)).
StyleFunc(func(row, col int) lipgloss.Style {
return lipgloss.NewStyle().Padding(0, 1)
})
Expand Down
4 changes: 2 additions & 2 deletions examples/table/languages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
BorderStyle = lipgloss.NewStyle().Foreground(purple)
)

rows := [][]any{
rows := [][]string{
{"Chinese", "您好", "你好"},
{"Japanese", "こんにちは", "やあ"},
{"Arabic", "أهلين", "أهلا"},
Expand Down Expand Up @@ -67,7 +67,7 @@ func main() {
return style
}).
Headers("LANGUAGE", "FORMAL", "INFORMAL").
Rows(rows...).
Rows(table.Rows(rows...)).
Width(18)

fmt.Println(t)
Expand Down
12 changes: 6 additions & 6 deletions examples/table/mindy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
labelStyle := re.NewStyle().Width(3).Align(lipgloss.Right)
swatchStyle := re.NewStyle().Width(6)

data := [][]any{}
data := [][]string{}
for i := 0; i < 13; i += 8 {
data = append(data, makeRow(i, i+5))
}
Expand All @@ -32,7 +32,7 @@ func main() {

t := table.New().
Border(lipgloss.HiddenBorder()).
Rows(data...).
Rows(table.Rows(data...)).
StyleFunc(func(row, col int) lipgloss.Style {
color := lipgloss.Color(fmt.Sprint(data[row-1][col-col%2]))
switch {
Expand All @@ -48,10 +48,10 @@ func main() {

const rowLength = 12

func makeRow(start, end int) []any {
var row []any
func makeRow(start, end int) []string {
var row []string
for i := start; i <= end; i++ {
row = append(row, i)
row = append(row, fmt.Sprint(i))
row = append(row, "")
}
for i := len(row); i < rowLength; i++ {
Expand All @@ -60,6 +60,6 @@ func makeRow(start, end int) []any {
return row
}

func makeEmptyRow() []any {
func makeEmptyRow() []string {
return makeRow(0, -1)
}
62 changes: 31 additions & 31 deletions examples/table/pokemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,35 @@ func main() {
}

headers := []any{"#", "Name", "Type 1", "Type 2", "Japanese", "Official Rom."}
data := [][]any{
{1, "Bulbasaur", "Grass", "Poison", "フシギダネ", "Bulbasaur"},
{2, "Ivysaur", "Grass", "Poison", "フシギソウ", "Ivysaur"},
{3, "Venusaur", "Grass", "Poison", "フシギバナ", "Venusaur"},
{4, "Charmander", "Fire", "", "ヒトカゲ", "Hitokage"},
{5, "Charmeleon", "Fire", "", "リザード", "Lizardo"},
{6, "Charizard", "Fire", "Flying", "リザードン", "Lizardon"},
{7, "Squirtle", "Water", "", "ゼニガメ", "Zenigame"},
{8, "Wartortle", "Water", "", "カメール", "Kameil"},
{9, "Blastoise", "Water", "", "カメックス", "Kamex"},
{10, "Caterpie", "Bug", "", "キャタピー", "Caterpie"},
{11, "Metapod", "Bug", "", "トランセル", "Trancell"},
{12, "Butterfree", "Bug", "Flying", "バタフリー", "Butterfree"},
{13, "Weedle", "Bug", "Poison", "ビードル", "Beedle"},
{14, "Kakuna", "Bug", "Poison", "コクーン", "Cocoon"},
{15, "Beedrill", "Bug", "Poison", "スピアー", "Spear"},
{16, "Pidgey", "Normal", "Flying", "ポッポ", "Poppo"},
{17, "Pidgeotto", "Normal", "Flying", "ピジョン", "Pigeon"},
{18, "Pidgeot", "Normal", "Flying", "ピジョット", "Pigeot"},
{19, "Rattata", "Normal", "", "コラッタ", "Koratta"},
{20, "Raticate", "Normal", "", "ラッタ", "Ratta"},
{21, "Spearow", "Normal", "Flying", "オニスズメ", "Onisuzume"},
{22, "Fearow", "Normal", "Flying", "オニドリル", "Onidrill"},
{23, "Ekans", "Poison", "", "アーボ", "Arbo"},
{24, "Arbok", "Poison", "", "アーボック", "Arbok"},
{25, "Pikachu", "Electric", "", "ピカチュウ", "Pikachu"},
{26, "Raichu", "Electric", "", "ライチュウ", "Raichu"},
{27, "Sandshrew", "Ground", "", "サンド", "Sand"},
{28, "Sandslash", "Ground", "", "サンドパン", "Sandpan"},
data := [][]string{
{"1", "Bulbasaur", "Grass", "Poison", "フシギダネ", "Bulbasaur"},
{"2", "Ivysaur", "Grass", "Poison", "フシギソウ", "Ivysaur"},
{"3", "Venusaur", "Grass", "Poison", "フシギバナ", "Venusaur"},
{"4", "Charmander", "Fire", "", "ヒトカゲ", "Hitokage"},
{"5", "Charmeleon", "Fire", "", "リザード", "Lizardo"},
{"6", "Charizard", "Fire", "Flying", "リザードン", "Lizardon"},
{"7", "Squirtle", "Water", "", "ゼニガメ", "Zenigame"},
{"8", "Wartortle", "Water", "", "カメール", "Kameil"},
{"9", "Blastoise", "Water", "", "カメックス", "Kamex"},
{"10", "Caterpie", "Bug", "", "キャタピー", "Caterpie"},
{"11", "Metapod", "Bug", "", "トランセル", "Trancell"},
{"12", "Butterfree", "Bug", "Flying", "バタフリー", "Butterfree"},
{"13", "Weedle", "Bug", "Poison", "ビードル", "Beedle"},
{"14", "Kakuna", "Bug", "Poison", "コクーン", "Cocoon"},
{"15", "Beedrill", "Bug", "Poison", "スピアー", "Spear"},
{"16", "Pidgey", "Normal", "Flying", "ポッポ", "Poppo"},
{"17", "Pidgeotto", "Normal", "Flying", "ピジョン", "Pigeon"},
{"18", "Pidgeot", "Normal", "Flying", "ピジョット", "Pigeot"},
{"19", "Rattata", "Normal", "", "コラッタ", "Koratta"},
{"20", "Raticate", "Normal", "", "ラッタ", "Ratta"},
{"21", "Spearow", "Normal", "Flying", "オニスズメ", "Onisuzume"},
{"22", "Fearow", "Normal", "Flying", "オニドリル", "Onidrill"},
{"23", "Ekans", "Poison", "", "アーボ", "Arbo"},
{"24", "Arbok", "Poison", "", "アーボック", "Arbok"},
{"25", "Pikachu", "Electric", "", "ピカチュウ", "Pikachu"},
{"26", "Raichu", "Electric", "", "ライチュウ", "Raichu"},
{"27", "Sandshrew", "Ground", "", "サンド", "Sand"},
{"28", "Sandslash", "Ground", "", "サンドパン", "Sandpan"},
}

CapitalizeHeaders := func(data []any) []any {
Expand All @@ -69,8 +69,8 @@ func main() {
Border(lipgloss.NormalBorder()).
BorderStyle(re.NewStyle().Foreground(lipgloss.Color("238"))).
Headers(CapitalizeHeaders(headers)...).
Width(40).
Rows(data...).
Width(80).
Rows(table.Rows(data...)).
StyleFunc(func(row, col int) lipgloss.Style {
if row == 0 {
return headerStyle
Expand Down

0 comments on commit 4f6f552

Please sign in to comment.