forked from Archives/fx
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
892 B
Go
41 lines
892 B
Go
2 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/charmbracelet/bubbles/key"
|
||
|
"github.com/charmbracelet/lipgloss"
|
||
|
"reflect"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
var helpStyle = lipgloss.NewStyle().PaddingLeft(4).PaddingTop(2).PaddingBottom(2)
|
||
|
|
||
|
func (m *model) helpView() []string {
|
||
|
v := reflect.ValueOf(m.keyMap)
|
||
|
fields := reflect.VisibleFields(v.Type())
|
||
|
|
||
|
keys := make([]string, 0)
|
||
|
for i := range fields {
|
||
|
k := v.Field(i).Interface().(key.Binding)
|
||
|
str := k.Help().Key
|
||
|
if width(str) == 0 {
|
||
|
str = strings.Join(k.Keys(), ", ")
|
||
|
}
|
||
|
keys = append(keys, fmt.Sprintf("%v ", str))
|
||
|
}
|
||
|
|
||
|
desc := make([]string, 0)
|
||
|
for i := range fields {
|
||
|
k := v.Field(i).Interface().(key.Binding)
|
||
|
desc = append(desc, fmt.Sprintf("%v", k.Help().Desc))
|
||
|
}
|
||
|
|
||
|
content := lipgloss.JoinHorizontal(
|
||
|
lipgloss.Top,
|
||
|
strings.Join(keys, "\n"),
|
||
|
strings.Join(desc, "\n"),
|
||
|
)
|
||
|
|
||
|
return strings.Split(helpStyle.Render(content), "\n")
|
||
|
}
|