Support different types of gutter messages

This commit is contained in:
Zachary Yedidia 2016-04-27 12:33:33 -04:00
parent cf8de5e11d
commit 53249c46f5
7 changed files with 135 additions and 104 deletions

View File

@ -554,7 +554,6 @@ 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: ")

View File

@ -56,6 +56,9 @@ type Messenger struct {
// We have to keep track of the cursor for prompting
cursorx int
// Is the current message a message from the gutter
gutterMessage bool
}
// Message sends a message to the user
@ -209,14 +212,19 @@ func (m *Messenger) Display() {
}
}
const (
GutterInfo = iota
GutterWarning
GutterError
)
// A GutterMessage is a message displayed on the side of the editor
type GutterMessage struct {
lineNum int
msg string
kind int
}
// These are the different types of messages
const (
// GutterInfo represents a simple info message
GutterInfo = iota
// GutterWarning represents a compiler warning
GutterWarning
// GutterError represents a compiler error
GutterError
)

File diff suppressed because one or more lines are too long

View File

@ -361,6 +361,7 @@ func (v *View) HandleEvent(event tcell.Event) {
}
}
// GutterMessage creates a message in this view's gutter
func (v *View) GutterMessage(lineN int, msg string, kind int) {
gutterMsg := GutterMessage{
lineNum: lineN,
@ -409,12 +410,28 @@ func (v *View) DisplayView() {
for _, msg := range v.messages {
if msg.lineNum == lineN+v.topline {
msgOnLine = true
screen.SetContent(x, lineN, '>', nil, tcell.StyleDefault)
gutterStyle := tcell.StyleDefault
switch msg.kind {
case GutterInfo:
if style, ok := colorscheme["gutter-info"]; ok {
gutterStyle = style
}
case GutterWarning:
if style, ok := colorscheme["gutter-warning"]; ok {
gutterStyle = style
}
case GutterError:
if style, ok := colorscheme["gutter-error"]; ok {
gutterStyle = style
}
}
screen.SetContent(x, lineN, '>', nil, gutterStyle)
x++
screen.SetContent(x, lineN, '>', nil, tcell.StyleDefault)
screen.SetContent(x, lineN, '>', nil, gutterStyle)
x++
if v.cursor.y == lineN {
messenger.Message(msg.msg)
messenger.gutterMessage = true
}
}
}
@ -423,8 +440,9 @@ func (v *View) DisplayView() {
x++
screen.SetContent(x, lineN, ' ', nil, tcell.StyleDefault)
x++
if v.cursor.y == lineN {
if v.cursor.y == lineN && messenger.gutterMessage {
messenger.Reset()
messenger.gutterMessage = false
}
}
}

View File

@ -8,4 +8,6 @@ color-link special "magenta"
color-link ignore "default"
color-link error ",brightred"
color-link todo ",brightyellow"
color-link line-number "yellow"
color-link line-number "yellow"
color-link gutter-error ",red"
color-link gutter-warning "red"

View File

@ -11,3 +11,5 @@ color-link error "bold #CB4B16,#002833"
color-link todo "bold #D33682,#002833"
color-link statusline "#003541,#839496"
color-link line-number "#586E75,#003541"
color-link gutter-error "#003541,#CB4B16"
color-link gutter-warning "#CB4B16,#002833"

View File

@ -10,3 +10,5 @@ color-link error "bold brightred"
color-link todo "bold magenta"
color-link statusline "black,brightblue"
color-link line-number "brightgreen,black"
color-link gutter-error "black,brightred"
color-link gutter-warning "brightred,default"