diff --git a/help.go b/help.go index a8eedd6..76e446f 100644 --- a/help.go +++ b/help.go @@ -8,10 +8,36 @@ import ( "strings" ) -var helpStyle = lipgloss.NewStyle().PaddingLeft(4).PaddingTop(2).PaddingBottom(2) +func usage(keyMap KeyMap) string { + title := lipgloss.NewStyle().Bold(true) + return fmt.Sprintf(`fx - terminal JSON viewer -func (m *model) helpView() []string { - v := reflect.ValueOf(m.keyMap) +%v + fx data.json + fx data.json .field + curl ... | fx + +%v +%v + +%v + [https://fx.wtf] +`, + title.Render("Usage"), + title.Render("Key Bindings"), + strings.Join( + keyMapInfo( + keyMap, + lipgloss.NewStyle().PaddingLeft(2), + ), + "\n", + ), + title.Render("More info"), + ) +} + +func keyMapInfo(keyMap KeyMap, style lipgloss.Style) []string { + v := reflect.ValueOf(keyMap) fields := reflect.VisibleFields(v.Type()) keys := make([]string, 0) @@ -36,5 +62,5 @@ func (m *model) helpView() []string { strings.Join(desc, "\n"), ) - return strings.Split(helpStyle.Render(content), "\n") + return strings.Split(style.Render(content), "\n") } diff --git a/main.go b/main.go index c24a1a4..34fe7a9 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" "github.com/mattn/go-isatty" "github.com/muesli/termenv" "golang.org/x/term" @@ -69,7 +70,7 @@ func main() { args = os.Args[1:] } if dec == nil { - fmt.Println("No input provided. Usage: `fx data.json` or `curl ... | fx`") + fmt.Println(usage(DefaultKeyMap())) os.Exit(1) } dec.UseNumber() @@ -446,7 +447,7 @@ func (m *model) render() { m.recalculateViewportHeight() if m.showHelp { - m.lines = m.helpView() + m.lines = keyMapInfo(m.keyMap, lipgloss.NewStyle().PaddingLeft(4).PaddingTop(2).PaddingBottom(2)) return }