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 {