-
Notifications
You must be signed in to change notification settings - Fork 8
feat: custom theme support #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
899ca85
2da0db2
3ca584f
6aff925
c8bf845
1732473
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,19 @@ import ( | |
| "sort" | ||
|
|
||
| "github.com/charmbracelet/lipgloss" | ||
|
|
||
| "os" | ||
|
|
||
| "path/filepath" | ||
|
|
||
| "github.com/BurntSushi/toml" | ||
|
|
||
| "fmt" | ||
| ) | ||
|
|
||
| // DefaultThemeName is the name of the default theme. | ||
| const DefaultThemeName = "GitHub Dark" | ||
|
|
||
| // Palette defines a set of colors for a theme. | ||
| type Palette struct { | ||
| Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, | ||
|
|
@@ -139,6 +150,20 @@ type TreeStyle struct { | |
| Connector, ConnectorLast, Prefix, PrefixLast string | ||
| } | ||
|
|
||
| //config.toml | ||
| type themeConfig struct{ | ||
| Theme string `toml:"theme"` | ||
| } | ||
|
|
||
| // custom_theme.toml | ||
| type ThemeFile struct{ | ||
| Fg string `toml:"fg"` | ||
| Bg string `toml:"bg"` | ||
| Normal map[string]string `toml:"normal"` | ||
| Bright map[string]string `toml:"bright"` | ||
| Dark map[string]string `toml:"dark"` | ||
| } | ||
|
|
||
| // Themes holds all the available themes, generated from palettes. | ||
| var Themes = map[string]Theme{} | ||
|
|
||
|
|
@@ -216,3 +241,49 @@ func ThemeNames() []string { | |
| sort.Strings(names) | ||
| return names | ||
| } | ||
|
|
||
| func load_config() (*themeConfig, error){ | ||
| cfgPath := filepath.Join(os.Getenv("HOME"), ".config", "gitx", "config.toml") | ||
| if _,err := os.Stat(cfgPath); os.IsNotExist(err) { | ||
| return &themeConfig{Theme: DefaultThemeName}, nil //fallback | ||
| } | ||
|
|
||
| var cfg themeConfig | ||
| if _, err := toml.DecodeFile(cfgPath, &cfg); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &cfg, nil | ||
| } | ||
|
|
||
| func load_custom_theme(name string) (*Palette, error){ | ||
| themePath := filepath.Join(os.Getenv("HOME"), ".config", "gitx", "themes", name+".toml") | ||
| if _,err := os.Stat(themePath); os.IsNotExist(err) { | ||
| return nil, fmt.Errorf("theme not found: %s", name) | ||
| } | ||
|
|
||
| var tf ThemeFile | ||
| if _, err := toml.DecodeFile(themePath, &tf); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Create a Palette from the ThemeFile | ||
| p := Palette{ | ||
| Fg: tf.Fg, | ||
| Bg: tf.Bg, | ||
| Black: tf.Normal["Black"], Red: tf.Normal["Red"], Green: tf.Normal["Green"], Yellow: tf.Normal["Yellow"], | ||
| Blue: tf.Normal["Blue"], Magenta: tf.Normal["Magenta"], Cyan: tf.Normal["Cyan"], White: tf.Normal["White"], | ||
|
|
||
| BrightBlack: tf.Bright["Black"], BrightRed: tf.Bright["Red"], BrightGreen: tf.Bright["Green"], BrightYellow: tf.Bright["Yellow"], | ||
| BrightBlue: tf.Bright["Blue"], BrightMagenta: tf.Bright["Magenta"], BrightCyan: tf.Bright["Cyan"], BrightWhite: tf.Bright["White"], | ||
|
|
||
| DarkBlack: tf.Dark["Black"], DarkRed: tf.Dark["Red"], DarkGreen: tf.Dark["Green"], DarkYellow: tf.Dark["Yellow"], | ||
| DarkBlue: tf.Dark["Blue"], DarkMagenta: tf.Dark["Magenta"], DarkCyan: tf.Dark["Cyan"], DarkWhite: tf.Dark["White"], | ||
|
|
||
| } | ||
|
|
||
| Palettes[name] = p // Add to Palettes map for future use | ||
| Themes[name] = NewThemeFromPalette(p) // Add to Themes map | ||
|
|
||
| return &p, nil | ||
| } | ||
|
Comment on lines
245
to
286
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although the scope of this PR does not include adding proper functionality for the user provided config file, that is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey, can you please clarify what you mean by "proper functionality" for the config file.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for not clarifying it properly.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah got it, thanks for clarifying, I'll ping you on discord so we can discuss and refactor together. |
||
Uh oh!
There was an error while loading. Please reload this page.