Skip to content

Commit

Permalink
Use colors from configuration and fallback to default hard coded values.
Browse files Browse the repository at this point in the history
  • Loading branch information
padawin committed Feb 2, 2023
1 parent 6357384 commit 8f1425e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
9 changes: 7 additions & 2 deletions internal/browser/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ func HandleCommandDefault() error {
log.Fatalln(err)
}

cfg, err := config.ReadConfig()
cfgPath, err := config.GetConfigPath()
if err != nil {
log.Fatalln(err)
}

cfg, err := config.ReadConfig(cfgPath)
if err != nil {
log.Fatalln(err)
}
Expand Down Expand Up @@ -85,7 +90,7 @@ func HandleCommandDefault() error {
}
defer f.Close()

model := NewModelWithItems(repos, gitConf.StoragePath(), gu)
model := NewModelWithItems(repos, gitConf.StoragePath(), gu, *cfg)
for {
if err := tea.NewProgram(model, tea.WithAltScreen(), tea.WithMouseAllMotion()).Start(); err != nil {
log.Fatalln(err)
Expand Down
10 changes: 7 additions & 3 deletions internal/browser/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"time"

"github.com/wmalik/ogit/internal/config"
"github.com/wmalik/ogit/internal/db"
"github.com/wmalik/ogit/internal/gitutils"

Expand All @@ -31,12 +32,15 @@ type Model struct {
gu *gitutils.GitUtils
}

func NewModelWithItems(repos []db.Repository, storagePath string, gu *gitutils.GitUtils) *Model {
func NewModelWithItems(repos []db.Repository, storagePath string, gu *gitutils.GitUtils, cfg config.Config) *Model {
listItems := sortItemsCloned(toItems(repos, storagePath))
m := list.NewModel(listItems, listItemDelegate(), 0, 0)
m := list.NewModel(listItems, listItemDelegate(cfg), 0, 0)
m.StatusMessageLifetime = time.Second * 60
m.Title = fmt.Sprintf("[ogit] [%s]", storagePath)
m.Styles.Title = titleBarStyle
m.Styles.Title = list.DefaultStyles().TitleBar.
Foreground(getColor(cfg.Colors.TitleBarFG, defaultTitleFg)).
Background(getColor(cfg.Colors.TitleBarBG, defaultTitleBg)).
Padding(0, 1)
m.AdditionalShortHelpKeys = availableKeyBindingsCB
m.KeyMap.GoToStart.SetKeys("home")
m.KeyMap.GoToStart.SetHelp("home", "go to start")
Expand Down
20 changes: 12 additions & 8 deletions internal/browser/style.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package browser

import (
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/lipgloss"
)

Expand All @@ -17,13 +16,11 @@ var bottomStatusBarStyle = lipgloss.NewStyle().Height(1).Faint(true)
var clonedRepoStyle = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#030303", Dark: "#dddddd"})

var dimmedColor = lipgloss.AdaptiveColor{Light: "#79787a", Dark: "#7F7C82"}
var selectedColorBg = lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#333333"}
var selectedColorFg = lipgloss.AdaptiveColor{Light: "#79787a", Dark: "#7F7C82"}
var titleBarStyle = list.DefaultStyles().TitleBar.
Background(lipgloss.AdaptiveColor{Light: "#5b186e", Dark: "#5b186e"}).
Foreground(lipgloss.AdaptiveColor{Light: "#f5f2f6", Dark: "#f5f2f6"}).
Padding(0, 1)
var defaultDimmedColorFg = lipgloss.AdaptiveColor{Light: "#79787a", Dark: "#7F7C82"}
var defaultSelectedColorBg = lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#333333"}
var defaultSelectedColorFg = lipgloss.AdaptiveColor{Light: "#79787a", Dark: "#7F7C82"}
var defaultTitleFg = lipgloss.AdaptiveColor{Light: "#f5f2f6", Dark: "#f5f2f6"}
var defaultTitleBg = lipgloss.AdaptiveColor{Light: "#5b186e", Dark: "#5b186e"}

func statusMessageStyle(str string) string {
return lipgloss.NewStyle().
Expand All @@ -36,3 +33,10 @@ func statusError(str string) string {
Foreground(lipgloss.AdaptiveColor{Light: "#eb4f34", Dark: "#eb4f34"}).
Render(str)
}

func getColor(color *lipgloss.AdaptiveColor, defaultColor lipgloss.AdaptiveColor) lipgloss.AdaptiveColor {
if color == nil {
return defaultColor
}
return *color
}
6 changes: 5 additions & 1 deletion internal/browser/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"

"github.com/wmalik/ogit/internal/config"
"github.com/wmalik/ogit/internal/shell"
"github.com/wmalik/ogit/internal/utils"

Expand Down Expand Up @@ -186,8 +187,11 @@ func handleKeyMsg(msg tea.KeyMsg, m *Model, selected repoItem) tea.Cmd {
}

// listItemDelegate configures general behaviour/styling of the list items.
func listItemDelegate() list.DefaultDelegate {
func listItemDelegate(cfg config.Config) list.DefaultDelegate {
d := list.NewDefaultDelegate()
dimmedColor := getColor(cfg.Colors.DimmedColorFG, defaultDimmedColorFg)
selectedColorFg := getColor(cfg.Colors.SelectedColorFG, defaultSelectedColorFg)
selectedColorBg := getColor(cfg.Colors.SelectedColorBG, defaultSelectedColorBg)
d.Styles.NormalTitle = d.Styles.NormalTitle.Foreground(dimmedColor)
d.Styles.SelectedTitle = d.Styles.SelectedTitle.Background(selectedColorBg).Foreground(selectedColorFg)
d.ShowDescription = false
Expand Down

0 comments on commit 8f1425e

Please sign in to comment.