diff --git a/sevenkeys/tui/constants.go b/sevenkeys/tui/constants.go new file mode 100644 index 0000000..2e3288b --- /dev/null +++ b/sevenkeys/tui/constants.go @@ -0,0 +1,50 @@ +package tui + +import "github.com/charmbracelet/bubbles/key" + +type KeyMappings struct { + Update key.Binding + SearchCriteria key.Binding + Search key.Binding + StorageOptions key.Binding + Find key.Binding + Quit key.Binding +} + +func (k KeyMappings) ShortHelp() []key.Binding { + return []key.Binding{k.Update, k.SearchCriteria, k.Search, k.StorageOptions, k.Find, k.Quit} +} + +func (k KeyMappings) FullHelp() [][]key.Binding { + return [][]key.Binding{ + {k.Update, k.SearchCriteria, k.Search}, + {k.StorageOptions, k.Find, k.Quit}, + } +} + +var KeyMap = KeyMappings{ + Update: key.NewBinding( + key.WithKeys("u"), + key.WithHelp("u", "update database"), + ), + SearchCriteria: key.NewBinding( + key.WithKeys("c"), + key.WithHelp("c", "card printing search criteria"), + ), + Search: key.NewBinding( + key.WithKeys("s"), + key.WithHelp("s", "card printing search"), + ), + StorageOptions: key.NewBinding( + key.WithKeys("o"), + key.WithHelp("o", "card storage options"), + ), + Find: key.NewBinding( + key.WithKeys("f"), + key.WithHelp("f", "find in storage"), + ), + Quit: key.NewBinding( + key.WithKeys("ctrl+c", "q"), + key.WithHelp("q", "quit program"), + ), +} diff --git a/sevenkeys/tui/home/model.go b/sevenkeys/tui/home/model.go index 85c3b78..7cf0407 100644 --- a/sevenkeys/tui/home/model.go +++ b/sevenkeys/tui/home/model.go @@ -2,56 +2,8 @@ package home import ( "github.com/charmbracelet/bubbles/help" - "github.com/charmbracelet/bubbles/key" ) -type KeyMap struct { - Update key.Binding - SearchCriteria key.Binding - Search key.Binding - StorageOptions key.Binding - Find key.Binding - Quit key.Binding -} - -func (k KeyMap) ShortHelp() []key.Binding { - return []key.Binding{k.Update, k.SearchCriteria, k.Search, k.StorageOptions, k.Find, k.Quit} -} - -func (k KeyMap) FullHelp() [][]key.Binding { - return [][]key.Binding{ - {k.Update, k.SearchCriteria, k.Search}, - {k.StorageOptions, k.Find, k.Quit}, - } -} - -var DefaultKeyMap = KeyMap{ - Update: key.NewBinding( - key.WithKeys("u"), - key.WithHelp("u", "update database"), - ), - SearchCriteria: key.NewBinding( - key.WithKeys("c"), - key.WithHelp("c", "card printing search criteria"), - ), - Search: key.NewBinding( - key.WithKeys("s"), - key.WithHelp("s", "card printing search"), - ), - StorageOptions: key.NewBinding( - key.WithKeys("o"), - key.WithHelp("o", "card storage options"), - ), - Find: key.NewBinding( - key.WithKeys("f"), - key.WithHelp("f", "find in storage"), - ), - Quit: key.NewBinding( - key.WithKeys("ctrl+c", "q"), - key.WithHelp("q", "quit program"), - ), -} - type Model struct { WindowHeight int WindowWidth int diff --git a/sevenkeys/tui/home/update.go b/sevenkeys/tui/home/update.go index 569b655..c6ef769 100644 --- a/sevenkeys/tui/home/update.go +++ b/sevenkeys/tui/home/update.go @@ -3,6 +3,8 @@ package home import ( "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" + + "sevenkeys/tui" ) func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { @@ -16,7 +18,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil case tea.KeyMsg: switch { - case key.Matches(msg, DefaultKeyMap.Quit): + case key.Matches(msg, tui.KeyMap.Quit): return m, tea.Quit } break diff --git a/sevenkeys/tui/home/view.go b/sevenkeys/tui/home/view.go index b098479..2e26868 100644 --- a/sevenkeys/tui/home/view.go +++ b/sevenkeys/tui/home/view.go @@ -3,6 +3,7 @@ package home import ( "os" "path/filepath" + "sevenkeys/tui" "strings" "github.com/lukesampson/figlet/figletlib" @@ -27,7 +28,7 @@ func (m Model) View() string { // Display help ui += strings.Repeat("\n", m.WindowHeight-8) // TODO: Avoid hardcoding height somehow - ui += m.Help.View(DefaultKeyMap) + ui += m.Help.View(tui.KeyMap) return ui }