keys.go

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