Skip to content

Commit

Permalink
feat(config): allow configuring ui and preview functions
Browse files Browse the repository at this point in the history
  • Loading branch information
idursun committed Mar 7, 2025
1 parent bf1c9b1 commit baba84c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
36 changes: 28 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,30 @@ import (
"path/filepath"
)

var Current = &Config{
Keys: DefaultKeyMappings,
UI: UIConfig{
HighlightLight: "#a0a0a0",
HighlightDark: "#282a36",
},
Preview: PreviewConfig{
ExtraArgs: []string{},
},
}

type Config struct {
Keys KeyMappings[keys] `toml:"keys"`
Keys KeyMappings[keys] `toml:"keys"`
UI UIConfig `toml:"ui"`
Preview PreviewConfig `toml:"preview"`
}

type UIConfig struct {
HighlightLight string `toml:"highlight_light"`
HighlightDark string `toml:"highlight_dark"`
}

type PreviewConfig struct {
ExtraArgs []string `toml:"extra_args"`
}

func getConfigFilePath() string {
Expand Down Expand Up @@ -41,19 +63,17 @@ func getDefaultEditor() string {
return editor
}

func Load() Config {
defaultConfig := Config{Keys: DefaultKeyMappings}
func Load() *Config {
configFile := getConfigFilePath()
_, err := os.Stat(configFile)
if err != nil {
return defaultConfig
return Current
}
_, err = toml.DecodeFile(configFile, &defaultConfig)
_, err = toml.DecodeFile(configFile, &Current)
if err != nil {
Current = &defaultConfig
return defaultConfig
return Current
}
return defaultConfig
return Current
}

func Edit() int {
Expand Down
11 changes: 9 additions & 2 deletions internal/jj/commands.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package jj

import "fmt"
import (
"fmt"
"github.com/idursun/jjui/internal/config"
)

type Commands interface{}

Expand Down Expand Up @@ -97,7 +100,11 @@ func GitPush() CommandArgs {
}

func Show(revision string) CommandArgs {
return []string{"show", "-r", revision, "--summary", "--git", "--ignore-all-space", "--color", "always"}
args := []string{"show", "-r", revision, "--color", "always"}
if config.Current.Preview.ExtraArgs != nil {
args = append(args, config.Current.Preview.ExtraArgs...)
}
return args
}

func Rebase(from string, to string, source string, target string) CommandArgs {
Expand Down
9 changes: 3 additions & 6 deletions internal/ui/common/styles.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package common

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

var (
Black = lipgloss.Color("0")
Expand All @@ -26,11 +28,6 @@ var DropStyle = lipgloss.NewStyle().
Foreground(Black).
Background(Red)

var HighlightedBackground = lipgloss.AdaptiveColor{
Light: "#A0A0A0",
Dark: "#282a36",
}

var DefaultPalette = Palette{
Normal: lipgloss.NewStyle(),
ImmutableNode: lipgloss.NewStyle().Foreground(IntenseCyan).Bold(true),
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/context/main_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type SelectedFile struct {
type MainContext struct {
selectedItem SelectedItem
location string
config config.Config
config *config.Config
}

func (a *MainContext) KeyMap() config.KeyMappings[key.Binding] {
Expand Down
6 changes: 5 additions & 1 deletion internal/ui/revisions/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,14 @@ func (m *Model) View() string {
w.Width = m.width
selectedLineStart := -1
selectedLineEnd := -1
highlightColor := lipgloss.AdaptiveColor{
Light: config.Current.UI.HighlightLight,
Dark: config.Current.UI.HighlightDark,
}
for i, row := range m.rows {
nodeRenderer := graph.DefaultRowRenderer{
Palette: common.DefaultPalette,
HighlightBackground: common.HighlightedBackground,
HighlightBackground: highlightColor,
Op: m.op,
IsHighlighted: i == m.cursor,
}
Expand Down

0 comments on commit baba84c

Please sign in to comment.