6 "github.com/zyedidia/micro/internal/display"
7 "github.com/zyedidia/micro/internal/info"
8 "github.com/zyedidia/micro/internal/util"
9 "github.com/zyedidia/tcell"
12 type InfoKeyAction func(*InfoPane)
14 type InfoPane struct {
19 func NewInfoPane(ib *info.InfoBuf, w display.BWindow) *InfoPane {
22 ip.BufPane = NewBufPane(ib.Buffer, w)
27 func NewInfoBar() *InfoPane {
28 ib := info.NewBuffer()
29 w := display.NewInfoWindow(ib)
30 return NewInfoPane(ib, w)
33 func (h *InfoPane) Close() {
38 func (h *InfoPane) HandleEvent(event tcell.Event) {
39 switch e := event.(type) {
47 done := h.DoKeyEvent(ke)
49 if e.Key() == tcell.KeyRune && hasYN {
50 if e.Rune() == 'y' && hasYN {
53 } else if e.Rune() == 'n' && hasYN {
58 if e.Key() == tcell.KeyRune && !done && !hasYN {
59 h.DoRuneInsert(e.Rune())
62 if done && h.HasPrompt && !hasYN {
63 resp := string(h.LineBytes(0))
64 hist := h.History[h.PromptType]
65 hist[h.HistoryNum] = resp
66 if h.EventCallback != nil {
70 case *tcell.EventMouse:
71 h.BufPane.HandleEvent(event)
75 func (h *InfoPane) DoKeyEvent(e KeyEvent) bool {
77 if action, ok := BufKeyBindings[e]; ok {
78 estr := BufKeyStrings[e]
79 for _, s := range InfoNones {
84 for s, a := range InfoOverrides {
92 done = action(h.BufPane)
98 // InfoNones is a list of actions that should have no effect when executed
100 var InfoNones = []string{
141 "SpawnMultiCursorSelect",
143 "RemoveAllMultiCursors",
147 // InfoOverrides is the list of actions which have been overriden
148 // by the infohandler
149 var InfoOverrides = map[string]InfoKeyAction{
150 "CursorUp": (*InfoPane).CursorUp,
151 "CursorDown": (*InfoPane).CursorDown,
152 "InsertNewline": (*InfoPane).InsertNewline,
153 "InsertTab": (*InfoPane).InsertTab,
154 "OutdentLine": (*InfoPane).CycleBack,
155 "Escape": (*InfoPane).Escape,
156 "Quit": (*InfoPane).Quit,
157 "QuitAll": (*InfoPane).QuitAll,
160 // CursorUp cycles history up
161 func (h *InfoPane) CursorUp() {
162 h.UpHistory(h.History[h.PromptType])
165 // CursorDown cycles history down
166 func (h *InfoPane) CursorDown() {
167 h.DownHistory(h.History[h.PromptType])
170 // InsertTab begins autocompletion
171 func (h *InfoPane) InsertTab() {
173 if b.HasSuggestions {
174 b.CycleAutocomplete(true)
178 c := b.GetActiveCursor()
180 l = util.SliceStart(l, c.X)
182 args := bytes.Split(l, []byte{' '})
183 cmd := string(args[0])
186 b.Autocomplete(CommandComplete)
188 if action, ok := commands[cmd]; ok {
189 if action.completer != nil {
190 b.Autocomplete(action.completer)
196 // CycleBack cycles back in the autocomplete suggestion list
197 func (h *InfoPane) CycleBack() {
198 if h.Buf.HasSuggestions {
199 h.Buf.CycleAutocomplete(false)
203 // InsertNewline completes the prompt
204 func (h *InfoPane) InsertNewline() {
210 // Quit cancels the prompt
211 func (h *InfoPane) Quit() {
215 // QuitAll cancels the prompt
216 func (h *InfoPane) QuitAll() {
220 // Escape cancels the prompt
221 func (h *InfoPane) Escape() {