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) *InfoPane {
23 ip.BufPane = NewBufPane(ib.Buffer, w)
28 func NewInfoBar() *InfoPane {
29 ib := info.NewBuffer()
30 w := display.NewInfoWindow(ib)
31 return NewInfoPane(ib, w)
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 func (h *InfoPane) DoKeyEvent(e KeyEvent) bool {
78 if action, ok := BufKeyBindings[e]; ok {
79 estr := BufKeyStrings[e]
80 for _, s := range InfoNones {
85 for s, a := range InfoOverrides {
86 // TODO this is a hack and really we should have support
87 // for having binding overrides for different buffers
88 if strings.Contains(estr, s) {
95 done = action(h.BufPane)
101 // InfoNones is a list of actions that should have no effect when executed
103 var InfoNones = []string{
144 "SpawnMultiCursorSelect",
146 "RemoveAllMultiCursors",
150 // InfoOverrides is the list of actions which have been overriden
151 // by the infohandler
152 var InfoOverrides = map[string]InfoKeyAction{
153 "CursorUp": (*InfoPane).CursorUp,
154 "CursorDown": (*InfoPane).CursorDown,
155 "InsertNewline": (*InfoPane).InsertNewline,
156 "Autocomplete": (*InfoPane).Autocomplete,
157 "OutdentLine": (*InfoPane).CycleBack,
158 "Escape": (*InfoPane).Escape,
159 "Quit": (*InfoPane).Quit,
160 "QuitAll": (*InfoPane).QuitAll,
163 // CursorUp cycles history up
164 func (h *InfoPane) CursorUp() {
165 h.UpHistory(h.History[h.PromptType])
168 // CursorDown cycles history down
169 func (h *InfoPane) CursorDown() {
170 h.DownHistory(h.History[h.PromptType])
173 // Autocomplete begins autocompletion
174 func (h *InfoPane) Autocomplete() {
176 if b.HasSuggestions {
177 b.CycleAutocomplete(true)
181 c := b.GetActiveCursor()
183 l = util.SliceStart(l, c.X)
185 args := bytes.Split(l, []byte{' '})
186 cmd := string(args[0])
189 b.Autocomplete(CommandComplete)
191 if action, ok := commands[cmd]; ok {
192 if action.completer != nil {
193 b.Autocomplete(action.completer)
199 // CycleBack cycles back in the autocomplete suggestion list
200 func (h *InfoPane) CycleBack() {
201 if h.Buf.HasSuggestions {
202 h.Buf.CycleAutocomplete(false)
206 // InsertNewline completes the prompt
207 func (h *InfoPane) InsertNewline() {
213 // Quit cancels the prompt
214 func (h *InfoPane) Quit() {
218 // QuitAll cancels the prompt
219 func (h *InfoPane) QuitAll() {
223 // Escape cancels the prompt
224 func (h *InfoPane) Escape() {