package ui import ( "fmt" "github.com/charmbracelet/bubbles/table" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" ) var baseStyle = lipgloss.NewStyle(). BorderStyle(lipgloss.NormalBorder()). BorderForeground(lipgloss.Color("240")) type model struct { table table.Model } func (m model) Init() tea.Cmd { return nil } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { case "q", "ctrl+c": return m, tea.Quit } } m.table, cmd = m.table.Update(msg) return m, cmd } func (m model) View() string { return baseStyle.Render(m.table.View()) + "\n " + m.table.HelpView() + "\n" } type TableTitle struct { Title string Width int } type Table struct { Titles []TableTitle Items [][]string } func (t *Table) Print() { columns := []table.Column{} for _, tit := range t.Titles { columns = append(columns, table.Column{ Title: tit.Title, Width: tit.Width, }) } rows := []table.Row{} for _, item := range t.Items { rows = append(rows, item) } tt := table.New( table.WithColumns(columns), table.WithRows(rows), table.WithFocused(true), // table.WithHeight(10), ) s := table.DefaultStyles() s.Header = s.Header. BorderStyle(lipgloss.NormalBorder()). BorderForeground(lipgloss.Color(THEMECOLOR)). BorderBottom(true). Bold(true) s.Selected = s.Selected. Foreground(lipgloss.Color(THEMECOLOR)). Bold(false) tt.SetStyles(s) m := model{tt} if _, err := tea.NewProgram(m).Run(); err != nil { ErrorWithExit(fmt.Sprintf("Error running program: %s", err.Error())) } }