From 3d40e91690f30658b30785e7a7aaea451c548d42 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 5 Aug 2019 20:43:34 -0700 Subject: [PATCH] Add log and plugin list command --- internal/action/bufpane.go | 6 ++++-- internal/action/command.go | 33 ++++++++++++++++++++++++++++++++- internal/action/globals.go | 31 +++++++++++++++++++++++++++++++ internal/buffer/buffer.go | 5 +++++ 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 9709fa52..86fb7e42 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -360,19 +360,21 @@ func (h *BufPane) DoRuneInsert(r rune) { } } -func (h *BufPane) VSplitBuf(buf *buffer.Buffer) { +func (h *BufPane) VSplitBuf(buf *buffer.Buffer) *BufPane { e := NewBufPaneFromBuf(buf) e.splitID = MainTab().GetNode(h.splitID).VSplit(h.Buf.Settings["splitright"].(bool)) MainTab().Panes = append(MainTab().Panes, e) MainTab().Resize() MainTab().SetActive(len(MainTab().Panes) - 1) + return e } -func (h *BufPane) HSplitBuf(buf *buffer.Buffer) { +func (h *BufPane) HSplitBuf(buf *buffer.Buffer) *BufPane { e := NewBufPaneFromBuf(buf) e.splitID = MainTab().GetNode(h.splitID).HSplit(h.Buf.Settings["splitbottom"].(bool)) MainTab().Panes = append(MainTab().Panes, e) MainTab().Resize() MainTab().SetActive(len(MainTab().Panes) - 1) + return e } func (h *BufPane) Close() { h.Buf.Close() diff --git a/internal/action/command.go b/internal/action/command.go index 029f9582..03949b0f 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -51,7 +51,7 @@ func InitCommands() { "tab": Command{(*BufPane).NewTabCmd, buffer.FileComplete}, "help": Command{(*BufPane).HelpCmd, HelpComplete}, "eval": Command{(*BufPane).EvalCmd, nil}, - "togglelog": Command{(*BufPane).ToggleLogCmd, nil}, + "log": Command{(*BufPane).ToggleLogCmd, nil}, "plugin": Command{(*BufPane).PluginCmd, nil}, "reload": Command{(*BufPane).ReloadCmd, nil}, "reopen": Command{(*BufPane).ReopenCmd, nil}, @@ -117,6 +117,30 @@ func CommandAction(cmd string) BufKeyAction { // PluginCmd installs, removes, updates, lists, or searches for given plugins func (h *BufPane) PluginCmd(args []string) { + if len(args) <= 0 { + InfoBar.Error("Not enough arguments, see 'help commands'") + return + } + + valid := true + switch args[0] { + case "list": + for _, pl := range config.Plugins { + var en string + if pl.IsEnabled() { + en = "enabled" + } else { + en = "disabled" + } + WriteLog(fmt.Sprintf("%s: %s\n", pl.Name, en)) + } + default: + valid = false + } + + if valid && h.Buf.Type != buffer.BTLog { + OpenLogBuf(h) + } } // RetabCmd changes all spaces to tabs or all tabs to spaces @@ -248,6 +272,11 @@ func (h *BufPane) OpenCmd(args []string) { // ToggleLogCmd toggles the log view func (h *BufPane) ToggleLogCmd(args []string) { + if h.Buf.Type != buffer.BTLog { + OpenLogBuf(h) + } else { + h.Quit() + } } // ReloadCmd reloads all files (syntax files, colorschemes...) @@ -818,6 +847,8 @@ func (h *BufPane) HandleCommand(input string) { if _, ok := commands[inputCmd]; !ok { InfoBar.Error("Unknown command ", inputCmd) } else { + WriteLog("> " + input + "\n") commands[inputCmd].action(h, args[1:]) + WriteLog("\n") } } diff --git a/internal/action/globals.go b/internal/action/globals.go index 301545c8..3884c212 100644 --- a/internal/action/globals.go +++ b/internal/action/globals.go @@ -1,11 +1,42 @@ package action +import "github.com/zyedidia/micro/internal/buffer" + var InfoBar *InfoPane +var LogBufPane *BufPane func InitGlobals() { InfoBar = NewInfoBar() + buffer.LogBuf = buffer.NewBufferFromString("", "Log", buffer.BTLog) } func GetInfoBar() *InfoPane { return InfoBar } + +func WriteLog(s string) { + buffer.WriteLog(s) + if LogBufPane != nil { + LogBufPane.CursorEnd() + v := LogBufPane.GetView() + endY := buffer.LogBuf.End().Y + + if endY > v.StartLine+v.Height { + v.StartLine = buffer.LogBuf.End().Y - v.Height + 2 + LogBufPane.SetView(v) + } + } +} + +func OpenLogBuf(h *BufPane) { + LogBufPane = h.HSplitBuf(buffer.LogBuf) + LogBufPane.CursorEnd() + + v := LogBufPane.GetView() + endY := buffer.LogBuf.End().Y + + if endY > v.StartLine+v.Height { + v.StartLine = buffer.LogBuf.End().Y - v.Height + 2 + LogBufPane.SetView(v) + } +} diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 7fe65d24..44f0e1e9 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -27,6 +27,7 @@ import ( var ( OpenBuffers []*Buffer + LogBuf *Buffer ) // The BufType defines what kind of buffer this is @@ -775,3 +776,7 @@ func ParseCursorLocation(cursorPositions []string) (Loc, error) { func (b *Buffer) Line(i int) string { return string(b.LineBytes(i)) } + +func WriteLog(s string) { + LogBuf.EventHandler.Insert(LogBuf.End(), s) +}