New theme key: include

Fixes #154
This commit is contained in:
makeworld 2021-12-28 19:43:24 -05:00
parent 33bf9603b5
commit cabc0660fd
19 changed files with 72 additions and 30 deletions

View File

@ -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)

View File

@ -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") {

View File

@ -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

View File

@ -1,4 +1,4 @@
[theme]
#[theme]
# Only the 256 xterm colors are used, so truecolor support is not needed

View File

@ -1,4 +1,4 @@
[theme]
#[theme]
# atelier forest light

View File

@ -1,4 +1,4 @@
[theme]
#[theme]
# atelier forest

View File

@ -1,4 +1,4 @@
[theme]
#[theme]
bg = "#282a36"
tab_num = "#bd93f9"
tab_divider = "#f8f8f2"

View File

@ -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".

View File

@ -1,4 +1,4 @@
[theme]
#[theme]
bg = "#ffffff"
tab_num = "#000000"
tab_divider = "#000000"

View File

@ -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".

View File

@ -1,4 +1,4 @@
[theme]
#[theme]
# Gruvbox Dark theme

View File

@ -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".

View File

@ -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".

View File

@ -1,7 +1,7 @@
# Atom One Dark theme ported to Amfora
# by Serge Tymoshenko <serge@tymo.name>
[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".

View File

@ -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".

View File

@ -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".

View File

@ -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".

View File

@ -1,4 +1,4 @@
[theme]
#[theme]
# Tokyo Night

View File

@ -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