44 "github.com/charmbracelet/bubbles/key"
55 "github.com/charmbracelet/bubbles/textinput"
66 tea "github.com/charmbracelet/bubbletea"
7- "github.com/maniac-en/req/internal/tui/keybinds"
87 "github.com/maniac-en/req/internal/tui/messages"
98 "github.com/maniac-en/req/internal/tui/styles"
109)
@@ -14,6 +13,7 @@ type OptionsInput struct {
1413 height int
1514 width int
1615 editId int64
16+ keys InputKeyMaps
1717}
1818
1919func NewOptionsInput (config * InputConfig ) OptionsInput {
@@ -27,6 +27,7 @@ func NewOptionsInput(config *InputConfig) OptionsInput {
2727 return OptionsInput {
2828 input : input ,
2929 editId : - 1 ,
30+ keys : config .KeyMap ,
3031 }
3132}
3233
@@ -40,14 +41,14 @@ func (i OptionsInput) Update(msg tea.Msg) (OptionsInput, tea.Cmd) {
4041 switch msg := msg .(type ) {
4142 case tea.KeyMsg :
4243 switch {
43- case key .Matches (msg , keybinds . Keys . Choose ):
44+ case key .Matches (msg , i . keys . Accept ):
4445 itemName := i .input .Value ()
4546 i .input .SetValue ("" )
4647 if i .editId == - 1 {
4748 return i , func () tea.Msg { return messages.ItemAdded {Item : itemName } }
4849 }
4950 return i , func () tea.Msg { return messages.ItemEdited {Item : itemName , ItemID : i .editId } }
50- case key .Matches (msg , keybinds . Keys .Back ):
51+ case key .Matches (msg , i . keys .Back ):
5152 return i , func () tea.Msg { return messages.DeactivateView {} }
5253 }
5354 }
@@ -62,6 +63,13 @@ func (i OptionsInput) View() string {
6263 return styles .InputStyle .Render (i .input .View ())
6364}
6465
66+ func (i OptionsInput ) Help () []key.Binding {
67+ return []key.Binding {
68+ i .keys .Accept ,
69+ i .keys .Back ,
70+ }
71+ }
72+
6573func (i * OptionsInput ) SetInput (text string ) {
6674 i .input .SetValue (text )
6775}
0 commit comments