7435512ffb
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
38 lines
783 B
Go
38 lines
783 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)
|
|
)
|
|
|
|
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
|
|
}
|