@@ 15,6 15,7 @@ import (
"git.src.quest/~skye/tamma/styles"
"git.src.quest/~skye/tamma/types"
+ "github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
@@ 37,6 38,7 @@ type model struct {
selectedHost types.HostItem
actionList list.Model
selectedAction types.ActionItem
+ actionListKeys *types.ActionListKeyMap
}
type execFinishedMsg struct{ err error }
@@ 192,12 194,23 @@ func main() {
if hostListH > 10 {
hostListH = 10
}
+ hostListKeys := types.NewHostListKeyMap()
hostList := list.New(hostListItems, types.HostItemDelegate{}, 48, hostListH+4)
hostList.Title = "Select host:"
- hostList.SetShowHelp(false)
+ hostList.SetShowHelp(true)
hostList.SetFilteringEnabled(true)
hostList.SetShowStatusBar(false)
hostList.DisableQuitKeybindings()
+ hostList.AdditionalShortHelpKeys = func() []key.Binding {
+ return []key.Binding{
+ hostListKeys.Quit,
+ }
+ }
+ hostList.AdditionalFullHelpKeys = func() []key.Binding {
+ return []key.Binding{
+ hostListKeys.Quit,
+ }
+ }
hostList.Styles.Title = styles.ListTitle
hostList.Styles.PaginationStyle = styles.ListPaginaton
@@ 227,19 240,33 @@ func main() {
if actionListH > 10 {
actionListH = 10
}
+ actionListKeys := types.NewActionListKeyMap()
actionList := list.New(actionListItems, types.ActionItemDelegate{}, 48, actionListH+4)
actionList.Title = "What shall we do today?"
- actionList.SetShowHelp(false)
+ actionList.SetShowHelp(true)
actionList.SetFilteringEnabled(true)
actionList.SetShowStatusBar(false)
actionList.DisableQuitKeybindings()
+ actionList.AdditionalShortHelpKeys = func() []key.Binding {
+ return []key.Binding{
+ actionListKeys.Back,
+ actionListKeys.CopyCommand,
+ }
+ }
+ actionList.AdditionalFullHelpKeys = func() []key.Binding {
+ return []key.Binding{
+ actionListKeys.Back,
+ actionListKeys.CopyCommand,
+ }
+ }
actionList.Styles.Title = styles.ListTitle
actionList.Styles.PaginationStyle = styles.ListPaginaton
p := tea.NewProgram(model{
- state: hostSelect,
- hostList: hostList,
- actionList: actionList,
+ state: hostSelect,
+ hostList: hostList,
+ actionList: actionList,
+ actionListKeys: actionListKeys,
}, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Printf("An error occured while running: %v\n", err)
@@ 0,0 1,47 @@
+/*
+ * Copyright (C) 2024 Jonni Liljamo <jonni@liljamo.com>
+ *
+ * This file is licensed under GPL-3.0-only, see NOTICE and LICENSE for
+ * more information.
+ */
+
+package types
+
+import (
+ "github.com/charmbracelet/bubbles/key"
+)
+
+// HostListKeyMap defines key bindings for the host list.
+type HostListKeyMap struct {
+ Quit key.Binding
+}
+
+// NewHostListKeyMap returns a new HostListKeyMap.
+func NewHostListKeyMap() *HostListKeyMap {
+ return &HostListKeyMap{
+ Quit: key.NewBinding(
+ key.WithKeys("q"),
+ key.WithHelp("q", "quit"),
+ ),
+ }
+}
+
+// ActionListKeyMap defines key bindings for the action list.
+type ActionListKeyMap struct {
+ Back key.Binding
+ CopyCommand key.Binding
+}
+
+// NewActionListKeyMap returns a new ActionListKeyMap.
+func NewActionListKeyMap() *ActionListKeyMap {
+ return &ActionListKeyMap{
+ Back: key.NewBinding(
+ key.WithKeys("q"),
+ key.WithHelp("q", "back"),
+ ),
+ CopyCommand: key.NewBinding(
+ key.WithKeys("c"),
+ key.WithHelp("c", "copy cmd"),
+ ),
+ }
+}