yr/cmd/internal/ui/table/table.go

39 lines
783 B
Go
Raw Normal View History

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)
)
t := table.New().
Border(lipgloss.RoundedBorder()).
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
}