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

🔧 Use shift_numbers - #64

This commit is contained in:
makeworld 2020-08-06 13:55:43 -04:00
parent 5fbef1e517
commit 70438cfdb5
7 changed files with 60 additions and 36 deletions

View File

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

View File

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

View File

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

View File

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

24
config/keybindings.go Normal file
View File

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

View File

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

View File

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