1package model
2
3import "charm.land/bubbles/v2/key"
4
5type KeyMap struct {
6 Editor struct {
7 AddFile key.Binding
8 SendMessage key.Binding
9 OpenEditor key.Binding
10 Newline key.Binding
11 AddImage key.Binding
12 MentionFile key.Binding
13
14 // Attachments key maps
15 AttachmentDeleteMode key.Binding
16 Escape key.Binding
17 DeleteAllAttachments key.Binding
18 }
19
20 Chat struct {
21 NewSession key.Binding
22 AddAttachment key.Binding
23 Cancel key.Binding
24 Tab key.Binding
25 Details key.Binding
26 Down key.Binding
27 Up key.Binding
28 DownOneItem key.Binding
29 UpOneItem key.Binding
30 PageDown key.Binding
31 PageUp key.Binding
32 HalfPageDown key.Binding
33 HalfPageUp key.Binding
34 Home key.Binding
35 End key.Binding
36 }
37
38 Initialize struct {
39 Yes,
40 No,
41 Enter,
42 Switch key.Binding
43 }
44
45 // Global key maps
46 Quit key.Binding
47 Help key.Binding
48 Commands key.Binding
49 Models key.Binding
50 Suspend key.Binding
51 Sessions key.Binding
52 Tab key.Binding
53}
54
55func DefaultKeyMap() KeyMap {
56 km := KeyMap{
57 Quit: key.NewBinding(
58 key.WithKeys("ctrl+c"),
59 key.WithHelp("ctrl+c", "quit"),
60 ),
61 Help: key.NewBinding(
62 key.WithKeys("ctrl+g"),
63 key.WithHelp("ctrl+g", "more"),
64 ),
65 Commands: key.NewBinding(
66 key.WithKeys("ctrl+p"),
67 key.WithHelp("ctrl+p", "commands"),
68 ),
69 Models: key.NewBinding(
70 key.WithKeys("ctrl+m", "ctrl+l"),
71 key.WithHelp("ctrl+l", "models"),
72 ),
73 Suspend: key.NewBinding(
74 key.WithKeys("ctrl+z"),
75 key.WithHelp("ctrl+z", "suspend"),
76 ),
77 Sessions: key.NewBinding(
78 key.WithKeys("ctrl+s"),
79 key.WithHelp("ctrl+s", "sessions"),
80 ),
81 Tab: key.NewBinding(
82 key.WithKeys("tab"),
83 key.WithHelp("tab", "change focus"),
84 ),
85 }
86
87 km.Editor.AddFile = key.NewBinding(
88 key.WithKeys("/"),
89 key.WithHelp("/", "add file"),
90 )
91 km.Editor.SendMessage = key.NewBinding(
92 key.WithKeys("enter"),
93 key.WithHelp("enter", "send"),
94 )
95 km.Editor.OpenEditor = key.NewBinding(
96 key.WithKeys("ctrl+o"),
97 key.WithHelp("ctrl+o", "open editor"),
98 )
99 km.Editor.Newline = key.NewBinding(
100 key.WithKeys("shift+enter", "ctrl+j"),
101 // "ctrl+j" is a common keybinding for newline in many editors. If
102 // the terminal supports "shift+enter", we substitute the help tex
103 // to reflect that.
104 key.WithHelp("ctrl+j", "newline"),
105 )
106 km.Editor.AddImage = key.NewBinding(
107 key.WithKeys("ctrl+f"),
108 key.WithHelp("ctrl+f", "add image"),
109 )
110 km.Editor.MentionFile = key.NewBinding(
111 key.WithKeys("@"),
112 key.WithHelp("@", "mention file"),
113 )
114 km.Editor.AttachmentDeleteMode = key.NewBinding(
115 key.WithKeys("ctrl+r"),
116 key.WithHelp("ctrl+r+{i}", "delete attachment at index i"),
117 )
118 km.Editor.Escape = key.NewBinding(
119 key.WithKeys("esc", "alt+esc"),
120 key.WithHelp("esc", "cancel delete mode"),
121 )
122 km.Editor.DeleteAllAttachments = key.NewBinding(
123 key.WithKeys("r"),
124 key.WithHelp("ctrl+r+r", "delete all attachments"),
125 )
126
127 km.Chat.NewSession = key.NewBinding(
128 key.WithKeys("ctrl+n"),
129 key.WithHelp("ctrl+n", "new session"),
130 )
131 km.Chat.AddAttachment = key.NewBinding(
132 key.WithKeys("ctrl+f"),
133 key.WithHelp("ctrl+f", "add attachment"),
134 )
135 km.Chat.Cancel = key.NewBinding(
136 key.WithKeys("esc", "alt+esc"),
137 key.WithHelp("esc", "cancel"),
138 )
139 km.Chat.Tab = key.NewBinding(
140 key.WithKeys("tab"),
141 key.WithHelp("tab", "change focus"),
142 )
143 km.Chat.Details = key.NewBinding(
144 key.WithKeys("ctrl+d"),
145 key.WithHelp("ctrl+d", "toggle details"),
146 )
147
148 km.Chat.Down = key.NewBinding(
149 key.WithKeys("down", "ctrl+j", "ctrl+n", "j"),
150 key.WithHelp("↓", "down"),
151 )
152 km.Chat.Up = key.NewBinding(
153 key.WithKeys("up", "ctrl+k", "ctrl+p", "k"),
154 key.WithHelp("↑", "up"),
155 )
156 km.Chat.UpOneItem = key.NewBinding(
157 key.WithKeys("shift+up", "K"),
158 key.WithHelp("shift+↑", "up one item"),
159 )
160 km.Chat.DownOneItem = key.NewBinding(
161 key.WithKeys("shift+down", "J"),
162 key.WithHelp("shift+↓", "down one item"),
163 )
164 km.Chat.HalfPageDown = key.NewBinding(
165 key.WithKeys("d"),
166 key.WithHelp("d", "half page down"),
167 )
168 km.Chat.PageDown = key.NewBinding(
169 key.WithKeys("pgdown", " ", "f"),
170 key.WithHelp("f/pgdn", "page down"),
171 )
172 km.Chat.PageUp = key.NewBinding(
173 key.WithKeys("pgup", "b"),
174 key.WithHelp("b/pgup", "page up"),
175 )
176 km.Chat.HalfPageUp = key.NewBinding(
177 key.WithKeys("u"),
178 key.WithHelp("u", "half page up"),
179 )
180 km.Chat.Home = key.NewBinding(
181 key.WithKeys("g", "home"),
182 key.WithHelp("g", "home"),
183 )
184 km.Chat.End = key.NewBinding(
185 key.WithKeys("G", "end"),
186 key.WithHelp("G", "end"),
187 )
188
189 km.Initialize.Yes = key.NewBinding(
190 key.WithKeys("y", "Y"),
191 key.WithHelp("y", "yes"),
192 )
193 km.Initialize.No = key.NewBinding(
194 key.WithKeys("n", "N", "esc", "alt+esc"),
195 key.WithHelp("n", "no"),
196 )
197 km.Initialize.Switch = key.NewBinding(
198 key.WithKeys("left", "right", "tab"),
199 key.WithHelp("tab", "switch"),
200 )
201 km.Initialize.Enter = key.NewBinding(
202 key.WithKeys("enter"),
203 key.WithHelp("enter", "select"),
204 )
205
206 return km
207}