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