From b69baa6aa0035cf0bc0c8b79b97bf9c1178772d6 Mon Sep 17 00:00:00 2001 From: Dolev Hadar Date: Tue, 27 Jun 2023 22:17:14 +0300 Subject: [PATCH] feat(ui): ability to hide table separator --- config/parser.go | 18 +++++++++++++++++- ui/components/table/table.go | 7 ++++++- ui/context/styles.go | 3 +-- ui/theme/theme.go | 2 +- ui/ui.go | 18 +++++++++++++++++- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/config/parser.go b/config/parser.go index b332609a..7775405a 100644 --- a/config/parser.go +++ b/config/parser.go @@ -142,8 +142,17 @@ type ColorThemeConfig struct { Inline ColorTheme `yaml:",inline" validate:"dive"` } +type TableUIThemeConfig struct { + ShowSeparator bool `yaml:"showSeparator" default:"true"` +} + +type UIThemeConfig struct { + Table TableUIThemeConfig `yaml:"table"` +} + type ThemeConfig struct { - Colors ColorThemeConfig `yaml:"colors,omitempty" validate:"dive"` + Ui UIThemeConfig `yaml:"ui,omitempty" validate:"dive"` + Colors *ColorThemeConfig `yaml:"colors,omitempty" validate:"omitempty,dive"` } type Config struct { @@ -248,6 +257,13 @@ func (parser ConfigParser) getDefaultConfig() Config { Prs: []Keybinding{}, }, RepoPaths: map[string]string{}, + Theme: &ThemeConfig{ + Ui: UIThemeConfig{ + Table: TableUIThemeConfig{ + ShowSeparator: true, + }, + }, + }, } } diff --git a/ui/components/table/table.go b/ui/components/table/table.go index 7a6e8e00..98ee83b0 100644 --- a/ui/components/table/table.go +++ b/ui/components/table/table.go @@ -38,6 +38,10 @@ func NewModel( itemTypeLabel string, emptyState *string, ) Model { + itemHeight := 1 + if ctx.Config.Theme.Ui.Table.ShowSeparator { + itemHeight = 2 + } return Model{ ctx: ctx, Columns: columns, @@ -50,7 +54,7 @@ func NewModel( lastUpdated, itemTypeLabel, len(rows), - 2, + itemHeight, ), } } @@ -242,6 +246,7 @@ func (m *Model) renderRow(rowId int, headerColumns []string) string { } return m.ctx.Styles.Table.RowStyle.Copy(). + BorderBottom(m.ctx.Config.Theme.Ui.Table.ShowSeparator). MaxWidth(m.dimensions.Width). Render(lipgloss.JoinHorizontal(lipgloss.Top, renderedColumns...)) diff --git a/ui/context/styles.go b/ui/context/styles.go index 42f62623..a6f8c29f 100644 --- a/ui/context/styles.go +++ b/ui/context/styles.go @@ -191,8 +191,7 @@ func InitStyles(theme theme.Theme) Styles { BorderBottom(true) s.Table.RowStyle = lipgloss.NewStyle(). BorderStyle(lipgloss.NormalBorder()). - BorderForeground(theme.FaintBorder). - BorderBottom(true) + BorderForeground(theme.FaintBorder) s.Tabs.Tab = lipgloss.NewStyle(). Faint(true). diff --git a/ui/theme/theme.go b/ui/theme/theme.go index 95213faf..6d39b157 100644 --- a/ui/theme/theme.go +++ b/ui/theme/theme.go @@ -37,7 +37,7 @@ func ParseTheme(cfg *config.Config) Theme { return lipgloss.AdaptiveColor{Light: string(hex), Dark: string(hex)} } - if cfg.Theme != nil { + if cfg.Theme.Colors != nil { DefaultTheme = &Theme{ SelectedBackground: _shimHex( cfg.Theme.Colors.Inline.Background.Selected, diff --git a/ui/ui.go b/ui/ui.go index 83e2adff..74e91f7a 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -87,7 +87,23 @@ func (m *Model) initScreen() tea.Msg { config, err := config.ParseConfig(m.ctx.ConfigPath) if err != nil { - log.Fatal("Error reading config", err) + log.KeyStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("1")). + Bold(true) + log.SeparatorStyle = lipgloss.NewStyle() + log.New( + log.WithTimeFormat(time.RFC3339), + log.WithTimestamp(), + log.WithPrefix("Reading config file"), + log.WithCaller(), + ). + Fatal( + "failed parsing config file", + "location", + m.ctx.ConfigPath, + "err", + err, + ) } return initMsg{Config: config}