|
| 1 | +// SPDX-License-Identifier: GPL-3.0-only |
| 2 | + |
| 3 | +package tui |
| 4 | + |
| 5 | +import "charm.land/bubbles/v2/key" |
| 6 | + |
| 7 | +// keyMap defines the key bindings for the application. |
| 8 | +type keyMap struct { |
| 9 | + Send key.Binding |
| 10 | + Cancel key.Binding |
| 11 | + History key.Binding |
| 12 | + PickFile key.Binding |
| 13 | + Quit key.Binding |
| 14 | +} |
| 15 | + |
| 16 | +// ShortHelp implements the help.KeyMap interface. Returns a slice of bindings to be |
| 17 | +// displayed in the short version of the help. The help bubble will render help in the |
| 18 | +// order in which the help items are returned here. |
| 19 | +func (k keyMap) ShortHelp() []key.Binding { |
| 20 | + return []key.Binding{k.Send, k.Cancel, k.History, k.PickFile, k.Quit} |
| 21 | +} |
| 22 | + |
| 23 | +// FullHelp implements the help.KeyMap interface. Returns an extended group of help |
| 24 | +// items, grouped by columns. The help bubble will render the help in the order in which |
| 25 | +// the help items are returned here. |
| 26 | +func (k keyMap) FullHelp() [][]key.Binding { |
| 27 | + return [][]key.Binding{k.ShortHelp()} |
| 28 | +} |
| 29 | + |
| 30 | +// defaultKeyMap returns the default key bindings for the application. |
| 31 | +func defaultKeyMap() keyMap { |
| 32 | + return keyMap{ |
| 33 | + Send: key.NewBinding(key.WithKeys("enter"), key.WithHelp("enter", "send")), |
| 34 | + Cancel: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "cancel")), |
| 35 | + History: key.NewBinding(key.WithKeys("up", "down"), key.WithHelp("↑/↓", "history")), |
| 36 | + PickFile: key.NewBinding(key.WithKeys("ctrl+p"), key.WithHelp("ctrl+p", "pick file")), |
| 37 | + Quit: key.NewBinding(key.WithKeys("ctrl+x"), key.WithHelp("ctrl+x", "quit")), |
| 38 | + } |
| 39 | +} |
0 commit comments