Merge branch 'gutter-messages'

This commit is contained in:
Zachary Yedidia
2016-04-27 12:33:45 -04:00
6 changed files with 183 additions and 94 deletions

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
@@ -208,3 +211,20 @@ func (m *Messenger) Display() {
screen.Show()
}
}
// 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

@@ -34,6 +34,8 @@ type View struct {
// The eventhandler for undo/redo
eh *EventHandler
messages []GutterMessage
// The buffer
buf *Buffer
// The statusline
@@ -360,6 +362,21 @@ 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,
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
@@ -376,6 +393,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
@@ -385,6 +406,48 @@ 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
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, gutterStyle)
x++
if v.cursor.y == lineN {
messenger.Message(msg.msg)
messenger.gutterMessage = true
}
}
}
if !msgOnLine {
screen.SetContent(x, lineN, ' ', nil, tcell.StyleDefault)
x++
screen.SetContent(x, lineN, ' ', nil, tcell.StyleDefault)
x++
if v.cursor.y == lineN && messenger.gutterMessage {
messenger.Reset()
messenger.gutterMessage = false
}
}
}
// Write the line number
lineNumStyle := defStyle
if style, ok := colorscheme["line-number"]; ok {

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"