7 "github.com/zyedidia/micro/internal/display"
8 "github.com/zyedidia/micro/internal/info"
9 "github.com/zyedidia/micro/internal/util"
10 "github.com/zyedidia/tcell"
13 type InfoKeyAction func(*InfoPane)
15 type InfoPane struct {
20 func NewInfoPane(ib *info.InfoBuf, w display.BWindow, tab *Tab) *InfoPane {
23 ip.BufPane = NewBufPane(ib.Buffer, w, tab)
28 func NewInfoBar() *InfoPane {
29 ib := info.NewBuffer()
30 w := display.NewInfoWindow(ib)
31 return NewInfoPane(ib, w, nil)
34 func (h *InfoPane) Close() {
39 func (h *InfoPane) HandleEvent(event tcell.Event) {
40 switch e := event.(type) {
48 done := h.DoKeyEvent(ke)
50 if e.Key() == tcell.KeyRune && hasYN {
51 if e.Rune() == 'y' && hasYN {
54 } else if e.Rune() == 'n' && hasYN {
59 if e.Key() == tcell.KeyRune && !done && !hasYN {
60 h.DoRuneInsert(e.Rune())
63 if done && h.HasPrompt && !hasYN {
64 resp := string(h.LineBytes(0))
65 hist := h.History[h.PromptType]
66 hist[h.HistoryNum] = resp
67 if h.EventCallback != nil {
71 case *tcell.EventMouse:
72 h.BufPane.HandleEvent(event)
76 // DoKeyEvent executes a key event for the command bar, doing any overridden actions
77 func (h *InfoPane) DoKeyEvent(e KeyEvent) bool {
79 if action, ok := BufKeyBindings[e]; ok {
80 estr := BufKeyStrings[e]
81 for _, s := range InfoNones {
86 for s, a := range InfoOverrides {
87 // TODO this is a hack and really we should have support
88 // for having binding overrides for different buffers
89 if strings.HasPrefix(estr, s) {
96 done = action(h.BufPane)
102 // InfoNones is a list of actions that should have no effect when executed
104 var InfoNones = []string{
146 "SpawnMultiCursorSelect",
148 "RemoveAllMultiCursors",
152 // InfoOverrides is the list of actions which have been overridden
153 // by the infohandler
154 var InfoOverrides = map[string]InfoKeyAction{
155 "CursorUp": (*InfoPane).CursorUp,
156 "CursorDown": (*InfoPane).CursorDown,
157 "InsertNewline": (*InfoPane).InsertNewline,
158 "Autocomplete": (*InfoPane).Autocomplete,
159 "Escape": (*InfoPane).Escape,
160 "Quit": (*InfoPane).Quit,
161 "QuitAll": (*InfoPane).QuitAll,
164 // CursorUp cycles history up
165 func (h *InfoPane) CursorUp() {
166 h.UpHistory(h.History[h.PromptType])
169 // CursorDown cycles history down
170 func (h *InfoPane) CursorDown() {
171 h.DownHistory(h.History[h.PromptType])
174 // Autocomplete begins autocompletion
175 func (h *InfoPane) Autocomplete() {
177 if b.HasSuggestions {
178 b.CycleAutocomplete(true)
182 c := b.GetActiveCursor()
184 l = util.SliceStart(l, c.X)
186 args := bytes.Split(l, []byte{' '})
187 cmd := string(args[0])
190 b.Autocomplete(CommandComplete)
192 if action, ok := commands[cmd]; ok {
193 if action.completer != nil {
194 b.Autocomplete(action.completer)
200 // InsertNewline completes the prompt
201 func (h *InfoPane) InsertNewline() {
207 // Quit cancels the prompt
208 func (h *InfoPane) Quit() {
212 // QuitAll cancels the prompt
213 func (h *InfoPane) QuitAll() {
217 // Escape cancels the prompt
218 func (h *InfoPane) Escape() {