diff --git a/cmd/forecast.go b/cmd/forecast.go index 28af1d7..5aacd29 100644 --- a/cmd/forecast.go +++ b/cmd/forecast.go @@ -45,6 +45,7 @@ func forecast(cmd *cobra.Command, args []string) { if !isUTC { item.Time = item.Time.Local() } + t.Row( item.Time.Format("Mon, 2 Jan 15:04"), fmt.Sprintf("%.1f °C", item.Temperature), diff --git a/cmd/internal/ui/table/table.go b/cmd/internal/ui/table/table.go index bc16aed..31bb454 100644 --- a/cmd/internal/ui/table/table.go +++ b/cmd/internal/ui/table/table.go @@ -16,22 +16,40 @@ func New() *table.Table { lightGray = lipgloss.Color("#dedede") ) var ( - HeaderStyle = re.NewStyle().Foreground(white).Bold(true).Align(lipgloss.Center) - CellStyle = re.NewStyle().Padding(0, 2) + HeaderStyle = re. + NewStyle(). + Foreground(white). + Bold(true). + Align(lipgloss.Center) + + CellStyle = re.NewStyle(). + Padding(0, 2). + AlignHorizontal(lipgloss.Right) + EvenRowStyle = CellStyle.Foreground(lightGray) ) t := table.New(). Border(lipgloss.RoundedBorder()). StyleFunc(func(row, col int) lipgloss.Style { - switch { - case row == 0: + if row == 0 { return HeaderStyle - case row%2 == 0: - return EvenRowStyle - default: - return CellStyle } + + var style lipgloss.Style + switch { + case row%2 == 0: + style = EvenRowStyle + default: + style = CellStyle + } + + // right align numeric values for better readability + if col > 0 && row > 1 { + style.AlignHorizontal(lipgloss.Right) + } + + return style }). Headers("time", "temp.", "rain", "wind") return t