@@ -4,13 +4,25 @@ import (
44 "github.com/charmbracelet/bubbles/key"
55 "github.com/charmbracelet/bubbles/textarea"
66 "github.com/charmbracelet/bubbles/viewport"
7+
8+ "github.com/j178/chatgpt"
79)
810
11+ type InputMode int
12+
13+ const (
14+ InputModelSingleLine InputMode = iota
15+ InputModelMultiLine
16+ )
17+
18+ func newBinding (keys []string , help string ) key.Binding {
19+ return key .NewBinding (key .WithKeys (keys ... ), key .WithHelp (keys [0 ], help ))
20+ }
21+
922type keyMap struct {
1023 SwitchMultiline key.Binding
1124 Submit key.Binding
12- ShowHelp key.Binding
13- HideHelp key.Binding
25+ ToggleHelp key.Binding
1426 Quit key.Binding
1527 Copy key.Binding
1628 PrevHistory key.Binding
@@ -25,7 +37,7 @@ type keyMap struct {
2537}
2638
2739func (k keyMap ) ShortHelp () []key.Binding {
28- return []key.Binding {k .ShowHelp }
40+ return []key.Binding {k .ToggleHelp }
2941}
3042
3143func (k keyMap ) FullHelp () [][]key.Binding {
@@ -43,30 +55,20 @@ func (k keyMap) FullHelp() [][]key.Binding {
4355 }
4456}
4557
46- func defaultKeyMap ( ) keyMap {
58+ func newKeyMap ( conf chatgpt. KeyMapConfig ) keyMap {
4759 return keyMap {
48- SwitchMultiline : key .NewBinding (key .WithKeys ("ctrl+j" ), key .WithHelp ("ctrl+j" , "multiline mode" )),
49- Submit : key .NewBinding (key .WithKeys ("enter" ), key .WithHelp ("enter" , "submit" )),
50- ShowHelp : key .NewBinding (key .WithKeys ("ctrl+h" ), key .WithHelp ("ctrl+h" , "show help" )),
51- HideHelp : key .NewBinding (key .WithKeys ("ctrl+h" ), key .WithHelp ("ctrl+h" , "hide help" )),
52- Quit : key .NewBinding (key .WithKeys ("esc" , "ctrl+c" ), key .WithHelp ("esc" , "quit" )),
53- Copy : key .NewBinding (key .WithKeys ("ctrl+y" ), key .WithHelp ("ctrl+y" , "copy last answer" )),
54- PrevHistory : key .NewBinding (key .WithKeys ("ctrl+p" ), key .WithHelp ("ctrl+p" , "previous question" )),
55- NextHistory : key .NewBinding (key .WithKeys ("ctrl+n" ), key .WithHelp ("ctrl+n" , "next question" )),
56- NewConversation : key .NewBinding (key .WithKeys ("ctrl+t" ), key .WithHelp ("ctrl+t" , "new conversation" )),
57- ForgetContext : key .NewBinding (key .WithKeys ("ctrl+x" ), key .WithHelp ("ctrl+x" , "forget context" )),
58- RemoveConversation : key .NewBinding (
59- key .WithKeys ("ctrl+r" ),
60- key .WithHelp ("ctrl+r" , "remove current conversation" ),
61- ),
62- PrevConversation : key .NewBinding (
63- key .WithKeys ("ctrl+left" , "ctrl+g" ),
64- key .WithHelp ("ctrl+left" , "previous conversation" ),
65- ),
66- NextConversation : key .NewBinding (
67- key .WithKeys ("ctrl+right" , "ctrl+o" ),
68- key .WithHelp ("ctrl+right" , "next conversation" ),
69- ),
60+ SwitchMultiline : newBinding (conf .SwitchMultiline , "multiline mode" ),
61+ Submit : newBinding (conf .Submit , "submit" ),
62+ ToggleHelp : newBinding (conf .Help , "toggle help" ),
63+ Quit : newBinding (conf .Quit , "quit" ),
64+ Copy : newBinding (conf .CopyLastAnswer , "copy last answer" ),
65+ PrevHistory : newBinding (conf .PreviousQuestion , "previous question" ),
66+ NextHistory : newBinding (conf .NextQuestion , "next question" ),
67+ NewConversation : newBinding (conf .NewConversation , "new conversation" ),
68+ ForgetContext : newBinding (conf .ForgetContext , "forget context" ),
69+ RemoveConversation : newBinding (conf .RemoveConversation , "remove current conversation" ),
70+ PrevConversation : newBinding (conf .PreviousConversation , "previous conversation" ),
71+ NextConversation : newBinding (conf .NextConversation , "next conversation" ),
7072 ViewPortKeys : viewport.KeyMap {
7173 PageDown : key .NewBinding (
7274 key .WithKeys ("pgdown" ),
@@ -115,34 +117,3 @@ func defaultKeyMap() keyMap {
115117 },
116118 }
117119}
118-
119- type InputMode int
120-
121- const (
122- InputModelSingleLine InputMode = iota
123- InputModelMultiLine
124- )
125-
126- func UseSingleLineInputMode (m * Model ) {
127- m .inputMode = InputModelSingleLine
128- m .keymap .SwitchMultiline = key .NewBinding (key .WithKeys ("ctrl+j" ), key .WithHelp ("ctrl+j" , "multiline mode" ))
129- m .keymap .Submit = key .NewBinding (key .WithKeys ("enter" ), key .WithHelp ("enter" , "submit" ))
130- m .keymap .TextAreaKeys .InsertNewline = key .NewBinding (
131- key .WithKeys ("ctrl+d" ),
132- key .WithHelp ("ctrl+d" , "insert new line" ),
133- )
134- m .viewport .KeyMap = m .keymap .ViewPortKeys
135- m .textarea .KeyMap = m .keymap .TextAreaKeys
136- }
137-
138- func UseMultiLineInputMode (m * Model ) {
139- m .inputMode = InputModelMultiLine
140- m .keymap .SwitchMultiline = key .NewBinding (key .WithKeys ("ctrl+j" ), key .WithHelp ("ctrl+j" , "single line mode" ))
141- m .keymap .Submit = key .NewBinding (key .WithKeys ("ctrl+d" ), key .WithHelp ("ctrl+d" , "submit" ))
142- m .keymap .TextAreaKeys .InsertNewline = key .NewBinding (
143- key .WithKeys ("enter" ),
144- key .WithHelp ("enter" , "insert new line" ),
145- )
146- m .viewport .KeyMap = m .keymap .ViewPortKeys
147- m .textarea .KeyMap = m .keymap .TextAreaKeys
148- }
0 commit comments