Skip to content

Commit

Permalink
New theme key: include
Browse files Browse the repository at this point in the history
Fixes #154
  • Loading branch information
makew0rld committed Dec 29, 2021
1 parent 33bf960 commit cabc066
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `header` config option in `[subscriptions]` to allow disabling the header text on the subscriptions page (#191)
- Selected link and scroll position stays for non-cached pages (#122)
- Keybinding to open URL with URL handler instead of configured proxy (#143)
- `include` theme key to import themes from an external file (#154)

### Changed
- Center text automatically, removing `left_margin` from the config (#233)
Expand Down
53 changes: 38 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,29 +347,52 @@ func Init() error {
cache.SetMaxPages(viper.GetInt("cache.max_pages"))
cache.SetTimeout(viper.GetInt("cache.timeout"))

setColor := func(k string, colorStr string) error {
colorStr = strings.ToLower(colorStr)
var color tcell.Color
if colorStr == "default" {
if strings.HasSuffix(k, "bg") {
color = tcell.ColorDefault
} else {
return fmt.Errorf(`"default" is only valid for a background color (color ending in "bg"), not "%s"`, k)
}
} else {
color = tcell.GetColor(colorStr)
if color == tcell.ColorDefault {
return fmt.Errorf(`invalid color format for "%s": %s`, k, colorStr)
}
}
SetColor(k, color)
return nil
}

// Setup theme
configTheme := viper.Sub("theme")
if configTheme != nil {
// Include key comes first
if incPath := configTheme.GetString("include"); incPath != "" {
incViper := viper.New()
incViper.SetConfigFile(incPath)
incViper.SetConfigType("toml")
err = incViper.ReadInConfig()
if err != nil {
return err
}

for k2, v2 := range incViper.AllSettings() {
colorStr, ok := v2.(string)
if !ok {
return fmt.Errorf(`include: value for "%s" is not a string: %v`, k2, v2)
}
setColor(k2, colorStr)
}
}
for k, v := range configTheme.AllSettings() {
colorStr, ok := v.(string)
if !ok {
return fmt.Errorf(`value for "%s" is not a string: %v`, k, v)
}
colorStr = strings.ToLower(colorStr)
var color tcell.Color
if colorStr == "default" {
if strings.HasSuffix(k, "bg") {
color = tcell.ColorDefault
} else {
return fmt.Errorf(`"default" is only valid for a background color (color ending in "bg"), not "%s"`, k)
}
} else {
color = tcell.GetColor(colorStr)
if color == tcell.ColorDefault {
return fmt.Errorf(`invalid color format for "%s": %s`, k, colorStr)
}
}
SetColor(k, color)
setColor(k, colorStr)
}
}
if viper.GetBool("a-general.color") {
Expand Down
9 changes: 9 additions & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,15 @@ header = true
# bottombar_bg
# scrollbar: The scrollbar that appears on the right for long pages
# You can also set an 'include' key to process another TOML file that contains theme keys.
# Example:
# include = "my/path/to/special-theme.toml"
#
# Any other theme keys will override this external file.
# You can use this special key to switch between themes easily.
# Download other themes here: https://github.com/makeworld-the-better-one/amfora/tree/master/contrib/themes
# hdg_1
# hdg_2
# hdg_3
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/amfora.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]

# Only the 256 xterm colors are used, so truecolor support is not needed

Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/atelier-forest-light.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]

# atelier forest light

Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/atelier-forest.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]

# atelier forest

Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/dracula-variant.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]
bg = "#282a36"
tab_num = "#bd93f9"
tab_divider = "#f8f8f2"
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/dracula.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]
# This section is for changing the COLORS used in Amfora.
# These colors only apply if 'color' is enabled above.
# Colors can be set using a W3C color name, or a hex value such as "#ffffff".
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/greyscale-light.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]
bg = "#ffffff"
tab_num = "#000000"
tab_divider = "#000000"
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/gruvbox.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]
# This section is for changing the COLORS used in Amfora.
# These colors only apply if 'color' is enabled above.
# Colors can be set using a W3C color name, or a hex value such as "#ffffff".
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/gruvbox_dark.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]

# Gruvbox Dark theme

Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/iceberg.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]
# This section is for changing the COLORS used in Amfora.
# These colors only apply if 'color' is enabled above.
# Colors can be set using a W3C color name, or a hex value such as "#ffffff".
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/nord.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]
# This section is for changing the COLORS used in Amfora.
# These colors only apply if 'color' is enabled above.
# Colors can be set using a W3C color name, or a hex value such as "#ffffff".
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/one_dark.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Atom One Dark theme ported to Amfora
# by Serge Tymoshenko <[email protected]>

[theme]
#[theme]
# This section is for changing the COLORS used in Amfora.
# These colors only apply if 'color' is enabled above.
# Colors can be set using a W3C color name, or a hex value such as "#ffffff".
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/slimey.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]
# This section is for changing the COLORS used in Amfora.
# These colors only apply if 'color' is enabled above.
# Colors can be set using a W3C color name, or a hex value such as "#ffffff".
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/solarized_dark.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]
# This section is for changing the COLORS used in Amfora.
# These colors only apply if 'color' is enabled above.
# Colors can be set using a W3C color name, or a hex value such as "#ffffff".
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/solarized_light.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]
# This section is for changing the COLORS used in Amfora.
# These colors only apply if 'color' is enabled above.
# Colors can be set using a W3C color name, or a hex value such as "#ffffff".
Expand Down
2 changes: 1 addition & 1 deletion contrib/themes/tokyo-night.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[theme]
#[theme]

# Tokyo Night

Expand Down
9 changes: 9 additions & 0 deletions default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ header = true
# bottombar_bg
# scrollbar: The scrollbar that appears on the right for long pages

# You can also set an 'include' key to process another TOML file that contains theme keys.
# Example:
# include = "my/path/to/special-theme.toml"
#
# Any other theme keys will override this external file.
# You can use this special key to switch between themes easily.
# Download other themes here: https://github.com/makeworld-the-better-one/amfora/tree/master/contrib/themes


# hdg_1
# hdg_2
# hdg_3
Expand Down

0 comments on commit cabc066

Please sign in to comment.