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