diff --git a/cmd/micro/bindings.go b/cmd/micro/bindings.go index d699da0a..8d31d39f 100644 --- a/cmd/micro/bindings.go +++ b/cmd/micro/bindings.go @@ -554,6 +554,7 @@ func (v *View) InsertTab() bool { // Save the buffer to disk func (v *View) Save() bool { + v.GutterMessage(4, "Hello", GutterInfo) // If this is an empty buffer, ask for a filename if v.buf.path == "" { filename, canceled := messenger.Prompt("Filename: ") diff --git a/cmd/micro/messenger.go b/cmd/micro/messenger.go index f482182f..99c0e1f4 100644 --- a/cmd/micro/messenger.go +++ b/cmd/micro/messenger.go @@ -208,3 +208,15 @@ func (m *Messenger) Display() { screen.Show() } } + +const ( + GutterInfo = iota + GutterWarning + GutterError +) + +type GutterMessage struct { + lineNum int + msg string + kind int +} diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 6a85c3d5..c83d39bc 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -34,6 +34,8 @@ type View struct { // The eventhandler for undo/redo eh *EventHandler + messages []GutterMessage + // The buffer buf *Buffer // The statusline @@ -359,6 +361,20 @@ func (v *View) HandleEvent(event tcell.Event) { } } +func (v *View) GutterMessage(lineN int, msg string, kind int) { + gutterMsg := GutterMessage{ + lineNum: lineN, + msg: msg, + kind: kind, + } + for _, gmsg := range v.messages { + if gmsg.lineNum == lineN { + return + } + } + v.messages = append(v.messages, gutterMsg) +} + // DisplayView renders the view to the screen func (v *View) DisplayView() { // The character number of the character in the top left of the screen @@ -375,6 +391,10 @@ func (v *View) DisplayView() { } var highlightStyle tcell.Style + if len(v.messages) > 0 { + v.lineNumOffset += 2 + } + for lineN := 0; lineN < v.height; lineN++ { var x int // If the buffer is smaller than the view height @@ -384,6 +404,31 @@ func (v *View) DisplayView() { } line := v.buf.lines[lineN+v.topline] + if len(v.messages) > 0 { + msgOnLine := false + for _, msg := range v.messages { + if msg.lineNum == lineN+v.topline { + msgOnLine = true + screen.SetContent(x, lineN, '>', nil, tcell.StyleDefault) + x++ + screen.SetContent(x, lineN, '>', nil, tcell.StyleDefault) + x++ + if v.cursor.y == lineN { + messenger.Message(msg.msg) + } + } + } + if !msgOnLine { + screen.SetContent(x, lineN, ' ', nil, tcell.StyleDefault) + x++ + screen.SetContent(x, lineN, ' ', nil, tcell.StyleDefault) + x++ + if v.cursor.y == lineN { + messenger.Reset() + } + } + } + // Write the line number lineNumStyle := defStyle if style, ok := colorscheme["line-number"]; ok {