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	Initialize struct {
 21		Yes,
 22		No,
 23		Switch key.Binding
 24	}
 25
 26	// Global key maps
 27	Quit     key.Binding
 28	Help     key.Binding
 29	Commands key.Binding
 30	Models   key.Binding
 31	Suspend  key.Binding
 32	Sessions key.Binding
 33	Tab      key.Binding
 34}
 35
 36func DefaultKeyMap() KeyMap {
 37	km := KeyMap{
 38		Quit: key.NewBinding(
 39			key.WithKeys("ctrl+c"),
 40			key.WithHelp("ctrl+c", "quit"),
 41		),
 42		Help: key.NewBinding(
 43			key.WithKeys("ctrl+g"),
 44			key.WithHelp("ctrl+g", "more"),
 45		),
 46		Commands: key.NewBinding(
 47			key.WithKeys("ctrl+p"),
 48			key.WithHelp("ctrl+p", "commands"),
 49		),
 50		Models: key.NewBinding(
 51			key.WithKeys("ctrl+m", "ctrl+l"),
 52			key.WithHelp("ctrl+l", "models"),
 53		),
 54		Suspend: key.NewBinding(
 55			key.WithKeys("ctrl+z"),
 56			key.WithHelp("ctrl+z", "suspend"),
 57		),
 58		Sessions: key.NewBinding(
 59			key.WithKeys("ctrl+s"),
 60			key.WithHelp("ctrl+s", "sessions"),
 61		),
 62		Tab: key.NewBinding(
 63			key.WithKeys("tab"),
 64			key.WithHelp("tab", "change focus"),
 65		),
 66	}
 67
 68	km.Editor.AddFile = key.NewBinding(
 69		key.WithKeys("/"),
 70		key.WithHelp("/", "add file"),
 71	)
 72	km.Editor.SendMessage = key.NewBinding(
 73		key.WithKeys("enter"),
 74		key.WithHelp("enter", "send"),
 75	)
 76	km.Editor.OpenEditor = key.NewBinding(
 77		key.WithKeys("ctrl+o"),
 78		key.WithHelp("ctrl+o", "open editor"),
 79	)
 80	km.Editor.Newline = key.NewBinding(
 81		key.WithKeys("shift+enter", "ctrl+j"),
 82		// "ctrl+j" is a common keybinding for newline in many editors. If
 83		// the terminal supports "shift+enter", we substitute the help tex
 84		// to reflect that.
 85		key.WithHelp("ctrl+j", "newline"),
 86	)
 87	km.Editor.AddImage = key.NewBinding(
 88		key.WithKeys("ctrl+f"),
 89		key.WithHelp("ctrl+f", "add image"),
 90	)
 91	km.Editor.MentionFile = key.NewBinding(
 92		key.WithKeys("@"),
 93		key.WithHelp("@", "mention file"),
 94	)
 95	km.Editor.AttachmentDeleteMode = key.NewBinding(
 96		key.WithKeys("ctrl+r"),
 97		key.WithHelp("ctrl+r+{i}", "delete attachment at index i"),
 98	)
 99	km.Editor.Escape = key.NewBinding(
100		key.WithKeys("esc", "alt+esc"),
101		key.WithHelp("esc", "cancel delete mode"),
102	)
103	km.Editor.DeleteAllAttachments = key.NewBinding(
104		key.WithKeys("r"),
105		key.WithHelp("ctrl+r+r", "delete all attachments"),
106	)
107
108	km.Initialize.Yes = key.NewBinding(
109		key.WithKeys("y", "Y"),
110		key.WithHelp("y", "yes"),
111	)
112	km.Initialize.No = key.NewBinding(
113		key.WithKeys("n", "N", "esc", "alt+esc"),
114		key.WithHelp("n", "no"),
115	)
116	km.Initialize.Switch = key.NewBinding(
117		key.WithKeys("left", "right", "tab"),
118		key.WithHelp("tab", "switch"),
119	)
120
121	return km
122}