mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-06 07:00:24 +09:00
Simple support for gutter messages
This commit is contained in:
@@ -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: ")
|
||||
|
||||
@@ -208,3 +208,15 @@ func (m *Messenger) Display() {
|
||||
screen.Show()
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
GutterInfo = iota
|
||||
GutterWarning
|
||||
GutterError
|
||||
)
|
||||
|
||||
type GutterMessage struct {
|
||||
lineNum int
|
||||
msg string
|
||||
kind int
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user