1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

add static hot key assignments for text widgets

This commit is contained in:
Mathias Weber 2018-10-15 22:51:35 +02:00
parent a48d15079a
commit 7d9dd56aaa
2 changed files with 26 additions and 4 deletions

View File

@ -29,9 +29,25 @@ func (tracker *FocusTracker) AssignHotKeys() {
return
}
usedKeys := make(map[string]bool)
focusables := tracker.focusables()
i := 1
for _, focusable := range tracker.focusables() {
for _, focusable := range focusables {
if focusable.FocusChar() != "" {
usedKeys[focusable.FocusChar()] = true
}
}
for _, focusable := range focusables {
if focusable.FocusChar() != "" {
continue
}
if _, foundKey := usedKeys[string('0'+i)]; foundKey {
for ; foundKey; _, foundKey = usedKeys[string('0'+i)] {
i++
}
}
// Don't have nav characters > "9"
if i >= 10 {
break

View File

@ -22,10 +22,16 @@ type TextWidget struct {
}
func NewTextWidget(app *tview.Application, name string, configKey string, focusable bool) TextWidget {
focusCharValue := Config.UInt(fmt.Sprintf("wtf.mods.%s.focusChar", configKey), -1)
focusChar := string('0' + focusCharValue)
if focusCharValue == -1 {
focusChar = ""
}
widget := TextWidget{
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
focusable: focusable,
focusChar: focusChar,
Name: Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name),
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
}