-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.go
46 lines (39 loc) · 892 Bytes
/
table.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package tui
import (
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
)
type Table struct {
*table.Table
}
func (t *Table) Row(row ...string) *Table {
t.Table.Row(row...)
return t
}
func (t *Table) RowIfNotEmpty(row ...string) *Table {
for _, cell := range row {
if cell == "" {
return t
}
}
t.Table.Row(row...)
return t
}
func BorderStyle(r *lipgloss.Renderer) lipgloss.Style {
return lipgloss.NewStyle().Renderer(r).
Foreground(lipgloss.AdaptiveColor{Light: "", Dark: "243"})
}
func MinimalTable(r *lipgloss.Renderer) *Table {
colStyle := BorderStyle(r).Padding(0, 1)
firstColStyle := colStyle.Copy().Align(lipgloss.Right).Bold(true)
return &Table{
Table: table.New().
BorderStyle(BorderStyle(r)).
StyleFunc(func(_, col int) lipgloss.Style {
if col == 0 {
return firstColStyle
}
return colStyle
}),
}
}