1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-19 19:25:24 +00:00

Added scrollbar config and themeing

This commit is contained in:
makeworld 2020-12-31 21:59:26 -05:00
parent c9073ceb26
commit c7d72a7875
6 changed files with 31 additions and 1 deletions

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- **Media type handlers** - open non-text files in another application (#121, #134)
- Ability to set custom keybindings in config (#135)
- Pages have a scrollbar by default (#89, #107)
### Changed
- Update cview to `c34e0954618b8e697819f88391ff3a492e990cb6` for large performance and feature updates (#107)

View File

@ -55,6 +55,10 @@ type MediaHandler struct {
var MediaHandlers = make(map[string]MediaHandler)
// Controlled by "a-general.scrollbar" in config
// Defaults to ScrollBarAuto on an invalid value
var ScrollBar cview.ScrollBarVisibility
func Init() error {
// *** Set paths ***
@ -204,6 +208,7 @@ func Init() error {
viper.SetDefault("a-general.page_max_size", 2097152)
viper.SetDefault("a-general.page_max_time", 10)
viper.SetDefault("a-general.emoji_favicons", false)
viper.SetDefault("a-general.scrollbar", "auto")
viper.SetDefault("keybindings.bind_reload", []string{"R", "Ctrl-R"})
viper.SetDefault("keybindings.bind_home", "Backspace")
viper.SetDefault("keybindings.bind_bookmarks", "Ctrl-B")
@ -392,5 +397,15 @@ func Init() error {
}
}
// Parse scrollbar options
switch viper.GetString("a-general.scrollbar") {
case "never":
ScrollBar = cview.ScrollBarNever
case "always":
ScrollBar = cview.ScrollBarAlways
default:
ScrollBar = cview.ScrollBarAuto
}
return nil
}

View File

@ -73,6 +73,10 @@ page_max_time = 10
# Whether to replace tab numbers with emoji favicons, which are cached.
emoji_favicons = false
# When a scrollbar appears. "never", "auto", and "always" are the only valid values.
# "auto" means the scrollbar only appears when the page is longer than the window.
scrollbar = "auto"
[auth]
# Authentication settings
@ -301,6 +305,7 @@ entries_per_page = 20
# bottombar_label: The color of the prompt that appears when you press space
# bottombar_text: The color of the text you type
# bottombar_bg
# scrollbar: The scrollbar that appears on the right for long pages
# hdg_1
# hdg_2

View File

@ -21,6 +21,7 @@ var theme = map[string]tcell.Color{
"bottombar_label": tcell.Color30,
"bottombar_text": tcell.ColorBlack,
"bottombar_bg": tcell.ColorWhite,
"scrollbar": tcell.ColorWhite,
// Modals
"btn_bg": tcell.ColorNavy, // All modal buttons

View File

@ -70,6 +70,10 @@ page_max_time = 10
# Whether to replace tab numbers with emoji favicons, which are cached.
emoji_favicons = false
# When a scrollbar appears. "never", "auto", and "always" are the only valid values.
# "auto" means the scrollbar only appears when the page is longer than the window.
scrollbar = "auto"
[auth]
# Authentication settings
@ -298,6 +302,7 @@ entries_per_page = 20
# bottombar_label: The color of the prompt that appears when you press space
# bottombar_text: The color of the text you type
# bottombar_bg
# scrollbar: The scrollbar that appears on the right for long pages
# hdg_1
# hdg_2

View File

@ -6,6 +6,7 @@ import (
"sync"
"github.com/gdamore/tcell/v2"
"github.com/makeworld-the-better-one/amfora/config"
"github.com/makeworld-the-better-one/amfora/structs"
"gitlab.com/tslocum/cview"
)
@ -46,11 +47,13 @@ func makeNewTab() *tab {
t.view.SetRegions(true)
t.view.SetScrollable(true)
t.view.SetWrap(false)
t.view.SetScrollBarVisibility(config.ScrollBar)
t.view.SetScrollBarColor(config.GetColor("scrollbar"))
t.view.SetChangedFunc(func() {
App.Draw()
})
t.view.SetDoneFunc(func(key tcell.Key) {
// Altered from: https://gitlab.com/tslocum/cview/-/blob/master/demos/textview/main.go
// Altered from: https://gitlab.com/tslocum/cview/-/blob/1f765c8695c3f4b35dae57f469d3aee0b1adbde7/demos/textview/main.go
// Handles being able to select and "click" links with the enter and tab keys
tab := curTab // Don't let it change in the middle of the code