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