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