Skip to content

Commit

Permalink
feat(ui): ability to hide table separator
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr committed Jun 29, 2023
1 parent 4e80368 commit b69baa6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
18 changes: 17 additions & 1 deletion config/parser.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -248,6 +257,13 @@ func (parser ConfigParser) getDefaultConfig() Config {
Prs: []Keybinding{},
},
RepoPaths: map[string]string{},
Theme: &ThemeConfig{
Ui: UIThemeConfig{
Table: TableUIThemeConfig{
ShowSeparator: true,
},
},
},
}
}

Expand Down
7 changes: 6 additions & 1 deletion ui/components/table/table.go
Expand Up @@ -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,
Expand All @@ -50,7 +54,7 @@ func NewModel(
lastUpdated,
itemTypeLabel,
len(rows),
2,
itemHeight,
),
}
}
Expand Down Expand Up @@ -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...))

Expand Down
3 changes: 1 addition & 2 deletions ui/context/styles.go
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion ui/theme/theme.go
Expand Up @@ -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,
Expand Down
18 changes: 17 additions & 1 deletion ui/ui.go
Expand Up @@ -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}
Expand Down

0 comments on commit b69baa6

Please sign in to comment.