7 "github.com/zyedidia/micro/v2/internal/buffer"
8 "github.com/zyedidia/micro/v2/internal/display"
9 "github.com/zyedidia/micro/v2/internal/info"
10 "github.com/zyedidia/micro/v2/internal/util"
11 "github.com/zyedidia/tcell"
14 type InfoKeyAction func(*InfoPane)
16 type InfoPane struct {
21 func NewInfoPane(ib *info.InfoBuf, w display.BWindow, tab *Tab) *InfoPane {
24 ip.BufPane = NewBufPane(ib.Buffer, w, tab)
29 func NewInfoBar() *InfoPane {
30 ib := info.NewBuffer()
31 w := display.NewInfoWindow(ib)
32 return NewInfoPane(ib, w, nil)
35 func (h *InfoPane) Close() {
40 func (h *InfoPane) HandleEvent(event tcell.Event) {
41 switch e := event.(type) {
49 done := h.DoKeyEvent(ke)
51 if e.Key() == tcell.KeyRune && hasYN {
52 if e.Rune() == 'y' && hasYN {
55 } else if e.Rune() == 'n' && hasYN {
60 if e.Key() == tcell.KeyRune && !done && !hasYN {
61 h.DoRuneInsert(e.Rune())
64 if done && h.HasPrompt && !hasYN {
65 resp := string(h.LineBytes(0))
66 hist := h.History[h.PromptType]
67 hist[h.HistoryNum] = resp
68 if h.EventCallback != nil {
73 h.BufPane.HandleEvent(event)
77 // DoKeyEvent executes a key event for the command bar, doing any overridden actions
78 func (h *InfoPane) DoKeyEvent(e KeyEvent) bool {
80 if action, ok := BufKeyBindings[e]; ok {
81 estr := BufKeyStrings[e]
82 for _, s := range InfoNones {
87 for s, a := range InfoOverrides {
88 // TODO this is a hack and really we should have support
89 // for having binding overrides for different buffers
90 if strings.HasPrefix(estr, s) {
97 done = action(h.BufPane)
103 // InfoNones is a list of actions that should have no effect when executed
105 var InfoNones = []string{
147 "SpawnMultiCursorSelect",
149 "RemoveAllMultiCursors",
153 // InfoOverrides is the list of actions which have been overridden
154 // by the infohandler
155 var InfoOverrides = map[string]InfoKeyAction{
156 "CursorUp": (*InfoPane).CursorUp,
157 "CursorDown": (*InfoPane).CursorDown,
158 "InsertNewline": (*InfoPane).InsertNewline,
159 "Autocomplete": (*InfoPane).Autocomplete,
160 "Escape": (*InfoPane).Escape,
161 "Quit": (*InfoPane).Quit,
162 "QuitAll": (*InfoPane).QuitAll,
165 // CursorUp cycles history up
166 func (h *InfoPane) CursorUp() {
167 h.UpHistory(h.History[h.PromptType])
170 // CursorDown cycles history down
171 func (h *InfoPane) CursorDown() {
172 h.DownHistory(h.History[h.PromptType])
175 // Autocomplete begins autocompletion
176 func (h *InfoPane) Autocomplete() {
178 if b.HasSuggestions {
179 b.CycleAutocomplete(true)
183 c := b.GetActiveCursor()
185 l = util.SliceStart(l, c.X)
187 args := bytes.Split(l, []byte{' '})
188 cmd := string(args[0])
190 if h.PromptType == "Command" {
192 b.Autocomplete(CommandComplete)
193 } else if action, ok := commands[cmd]; ok {
194 if action.completer != nil {
195 b.Autocomplete(action.completer)
199 // by default use filename autocompletion
200 b.Autocomplete(buffer.FileComplete)
204 // InsertNewline completes the prompt
205 func (h *InfoPane) InsertNewline() {
211 // Quit cancels the prompt
212 func (h *InfoPane) Quit() {
216 // QuitAll cancels the prompt
217 func (h *InfoPane) QuitAll() {
221 // Escape cancels the prompt
222 func (h *InfoPane) Escape() {