From 70438cfdb5fc84b7375a96a195330ac09b5dd404 Mon Sep 17 00:00:00 2001 From: makeworld Date: Thu, 6 Aug 2020 13:55:43 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Use=20shift=5Fnumbers=20-=20#64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + README.md | 4 ++-- config/config.go | 1 + config/default.go | 11 ++++++++++- config/keybindings.go | 24 +++++++++++++++++++++++ default-config.toml | 11 ++++++++++- display/display.go | 44 ++++++++++++------------------------------- 7 files changed, 60 insertions(+), 36 deletions(-) create mode 100644 config/keybindings.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ac84f8..1bccc07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - Emoji favicons can now be seen if `emoji_favicons` is enabled in the config (#62) +- The `shift_numbers` key in the config was added, so that non US keyboard users can navigate tabs (#64) ### Changed diff --git a/README.md b/README.md index 074d95d..243b639 100644 --- a/README.md +++ b/README.md @@ -95,10 +95,10 @@ Features in *italics* are in the master branch, but not in the latest release. - [x] Bookmarks - [x] Download pages and arbitrary data - [x] Theming -- [ ] Subscribe to RSS and Atom feeds and display them - - Subscribing to page changes, similar to how Spacewalk works, will also be supported - [x] *Emoji favicons* - See `gemini://mozz.us/files/rfc_gemini_favicon.gmi` for details +- [ ] Subscribe to RSS and Atom feeds and display them + - Subscribing to page changes, similar to how Spacewalk works, will also be supported - [ ] Stream support - [ ] Full client certificate UX within the client - Create transient and permanent certs within the client, per domain diff --git a/config/config.go b/config/config.go index f7b9f20..528b7c4 100644 --- a/config/config.go +++ b/config/config.go @@ -154,6 +154,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("keybindings.shift_numbers", "!@#$%^&*()") viper.SetDefault("cache.max_size", 0) viper.SetDefault("cache.max_pages", 20) diff --git a/config/default.go b/config/default.go index ec226b3..b191984 100644 --- a/config/default.go +++ b/config/default.go @@ -11,6 +11,7 @@ var defaultConf = []byte(`# This is the default config file. # example.com # example.com:123 + [a-general] # Press Ctrl-H to access it home = "gemini://gemini.circumlunar.space" @@ -49,10 +50,18 @@ page_max_time = 10 # Whether to replace tab numbers with emoji favicons, which are cached. emoji_favicons = false +[keybindings] +# In the future there will be more settings here. +# Hold down shift and press the numbers on your keyboard (1,2,3,4,5,6,7,8,9,0) to set this up. +# It is default set to be accurate for US keyboards. +shift_numbers = "!@#$%^&*()" + + +[cache] # Options for page cache - which is only for text/gemini pages # Increase the cache size to speed up browsing at the expense of memory -[cache] + # Zero values mean there is no limit max_size = 0 # Size in bytes max_pages = 30 # The maximum number of pages the cache will store diff --git a/config/keybindings.go b/config/keybindings.go new file mode 100644 index 0000000..ccc7310 --- /dev/null +++ b/config/keybindings.go @@ -0,0 +1,24 @@ +package config + +import ( + "errors" + + "github.com/spf13/viper" +) + +// KeyToNum returns the number on the user's keyboard they pressed, +// using the rune returned when when they press Shift+Num. +// The error is not nil if the provided key is invalid. +func KeyToNum(key rune) (int, error) { + runes := []rune(viper.GetString("keybindings.shift_numbers")) + for i := range runes { + if key == runes[i] { + if i == len(runes)-1 { + // Last key is 0, not 10 + return 0, nil + } + return i + 1, nil + } + } + return -1, errors.New("provided key is invalid") +} diff --git a/default-config.toml b/default-config.toml index 8df3777..3dff68d 100644 --- a/default-config.toml +++ b/default-config.toml @@ -8,6 +8,7 @@ # example.com # example.com:123 + [a-general] # Press Ctrl-H to access it home = "gemini://gemini.circumlunar.space" @@ -46,10 +47,18 @@ page_max_time = 10 # Whether to replace tab numbers with emoji favicons, which are cached. emoji_favicons = false +[keybindings] +# In the future there will be more settings here. +# Hold down shift and press the numbers on your keyboard (1,2,3,4,5,6,7,8,9,0) to set this up. +# It is default set to be accurate for US keyboards. +shift_numbers = "!@#$%^&*()" + + +[cache] # Options for page cache - which is only for text/gemini pages # Increase the cache size to speed up browsing at the expense of memory -[cache] + # Zero values mean there is no limit max_size = 0 # Size in bytes max_pages = 30 # The maximum number of pages the cache will store diff --git a/display/display.go b/display/display.go index 20f1b70..6815e2d 100644 --- a/display/display.go +++ b/display/display.go @@ -354,6 +354,18 @@ func Init() { return nil case tcell.KeyRune: // Regular key was sent + + if num, err := config.KeyToNum(event.Rune()); err == nil { + // It's a Shift+Num key + if num == 0 { + // Zero key goes to the last tab + SwitchTab(NumTabs() - 1) + } else { + SwitchTab(num - 1) + } + return nil + } + switch string(event.Rune()) { case "q": Stop() @@ -361,38 +373,6 @@ func Init() { case "?": Help() return nil - - // Shift+NUMBER keys, for switching to a specific tab - case "!": - SwitchTab(0) - return nil - case "@": - SwitchTab(1) - return nil - case "#": - SwitchTab(2) - return nil - case "$": - SwitchTab(3) - return nil - case "%": - SwitchTab(4) - return nil - case "^": - SwitchTab(5) - return nil - case "&": - SwitchTab(6) - return nil - case "*": - SwitchTab(7) - return nil - case "(": - SwitchTab(8) - return nil - case ")": // Zero key goes to the last tab - SwitchTab(NumTabs() - 1) - return nil } }