1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-12-04 14:46:37 -05:00

Refactored keymap help, fixed sorting of forums

This commit is contained in:
マリウス 2023-01-05 19:55:52 -05:00
parent 520686204e
commit 42e9987d29
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
3 changed files with 25 additions and 16 deletions

View File

@ -43,7 +43,7 @@ func (a *Aggregator) ListForums() ([]forum.Forum, []error) {
}
sort.SliceStable(forums, func(i, j int) bool {
return strings.Compare(forums[i].Name, forums[j].Name) == 1
return strings.Compare(forums[i].Name, forums[j].Name) == -1
})
return forums, errs

View File

@ -19,13 +19,7 @@ func (tk *ToolKit) Dialog(title string, content string, bbar bool) string {
Width(tk.ViewWidth()).
Render(title)
var bindings []string
for _, binding := range tk.keybindings {
var tmp string = ""
tmp = binding.Help().Key + " " + binding.Help().Desc
bindings = append(bindings, tmp)
}
bindings = append(bindings, "esc close")
bindings := tk.KeymapHelpStrings()
var ui string
if bbar {
@ -72,13 +66,7 @@ func (tk *ToolKit) ErrorDialog(title string, content string) string {
Width(tk.ViewWidth()).
Render(title)
var bindings []string
for _, binding := range tk.keybindings {
var tmp string = ""
tmp = binding.Help().Key + " " + binding.Help().Desc
bindings = append(bindings, tmp)
}
bindings = append(bindings, "esc close")
bindings := tk.KeymapHelpStrings()
bottombar := tk.theme.ErrorDialogBox.Bottombar.
Width(tk.ViewWidth()).

View File

@ -1,6 +1,11 @@
package toolkit
import "github.com/charmbracelet/bubbles/key"
import (
"sort"
"strings"
"github.com/charmbracelet/bubbles/key"
)
func (tk *ToolKit) KeymapAdd(id string, help string, keys ...string) {
keysview := ""
@ -28,3 +33,19 @@ func (tk *ToolKit) KeymapGet(id string) key.Binding {
return key.NewBinding()
}
func (tk *ToolKit) KeymapHelpStrings() []string {
var bindings []string
for _, binding := range tk.keybindings {
var tmp string = ""
tmp = binding.Help().Key + " " + binding.Help().Desc
bindings = append(bindings, tmp)
}
sort.SliceStable(bindings, func(i, j int) bool {
return strings.Compare(bindings[i], bindings[j]) == -1
})
bindings = append(bindings, "esc close")
return bindings
}