2024-10-03 20:37:54 +00:00
|
|
|
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().
|
2024-10-05 16:33:20 +00:00
|
|
|
Border(lipgloss.RoundedBorder()).
|
2024-10-03 20:37:54 +00:00
|
|
|
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
|
|
|
|
}
|