49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package pretty
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/charmbracelet/lipgloss"
|
|
"github.com/charmbracelet/lipgloss/table"
|
|
)
|
|
|
|
var (
|
|
rows = [][]string{
|
|
{"Chinese", "您好", "你好"},
|
|
{"Japanese", "こんにちは", "やあ"},
|
|
{"Arabic", "أهلين", "أهلا"},
|
|
{"Russian", "Здравствуйте", "Привет"},
|
|
{"Spanish", "Hola", "¿Qué tal?"},
|
|
}
|
|
|
|
purple = lipgloss.Color("99")
|
|
gray = lipgloss.Color("245")
|
|
lightGray = lipgloss.Color("241")
|
|
|
|
headerStyle = lipgloss.NewStyle().Foreground(purple).Bold(true).Align(lipgloss.Center)
|
|
cellStyle = lipgloss.NewStyle().Padding(0, 1)
|
|
oddRowStyle = cellStyle.Foreground(gray)
|
|
evenRowStyle = cellStyle.Foreground(lightGray)
|
|
)
|
|
|
|
func Table(headers []string, rows [][]string) {
|
|
t := table.New().
|
|
Border(lipgloss.NormalBorder()).
|
|
BorderStyle(lipgloss.NewStyle().Foreground(purple)).
|
|
StyleFunc(func(row, col int) lipgloss.Style {
|
|
switch {
|
|
case row == table.HeaderRow:
|
|
return headerStyle
|
|
case row%2 == 0:
|
|
return evenRowStyle
|
|
default:
|
|
return oddRowStyle
|
|
}
|
|
}).
|
|
Headers(headers...).
|
|
Rows(rows...)
|
|
|
|
// You can also add tables row-by-row
|
|
//t.Row("English", "You look absolutely fabulous.", "How's it going?")
|
|
fmt.Println(t)
|
|
}
|