41 lines
865 B
Go
41 lines
865 B
Go
|
package table
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
|
"github.com/charmbracelet/lipgloss"
|
||
|
"github.com/charmbracelet/lipgloss/table"
|
||
|
)
|
||
|
|
||
|
// TODO: Make more generic
|
||
|
func New() *table.Table {
|
||
|
re := lipgloss.NewRenderer(os.Stdout)
|
||
|
|
||
|
const (
|
||
|
white = lipgloss.Color("#fff")
|
||
|
lightGray = lipgloss.Color("#dedede")
|
||
|
)
|
||
|
var (
|
||
|
HeaderStyle = re.NewStyle().Foreground(white).Bold(true).Align(lipgloss.Center)
|
||
|
CellStyle = re.NewStyle().Padding(0, 2)
|
||
|
EvenRowStyle = CellStyle.Foreground(lightGray)
|
||
|
BorderStyle = lipgloss.NewStyle().Foreground(white)
|
||
|
)
|
||
|
|
||
|
t := table.New().
|
||
|
Border(lipgloss.NormalBorder()).
|
||
|
BorderStyle(BorderStyle).
|
||
|
StyleFunc(func(row, col int) lipgloss.Style {
|
||
|
switch {
|
||
|
case row == 0:
|
||
|
return HeaderStyle
|
||
|
case row%2 == 0:
|
||
|
return EvenRowStyle
|
||
|
default:
|
||
|
return CellStyle
|
||
|
}
|
||
|
}).
|
||
|
Headers("time", "temp.", "rain", "wind")
|
||
|
return t
|
||
|
}
|