micro/statusline.go

37 lines
831 B
Go
Raw Normal View History

2016-03-17 22:20:07 +00:00
package main
import (
"github.com/gdamore/tcell"
"strconv"
)
2016-03-19 00:40:00 +00:00
// Statusline represents the blue line at the bottom of the
// editor that gives information about the buffer
2016-03-17 22:20:07 +00:00
type Statusline struct {
v *View
}
2016-03-19 00:40:00 +00:00
// Display draws the statusline to the screen
func (sl *Statusline) Display() {
2016-03-17 22:20:07 +00:00
y := sl.v.height
file := sl.v.buf.name
if file == "" {
file = "Untitled"
}
if sl.v.buf.text != sl.v.buf.savedText {
file += " +"
}
2016-03-19 00:40:00 +00:00
file += " (" + strconv.Itoa(sl.v.cursor.y+1) + "," + strconv.Itoa(sl.v.cursor.GetVisualX()+1) + ")"
2016-03-17 22:20:07 +00:00
statusLineStyle := tcell.StyleDefault.Background(tcell.ColorNavy).Foreground(tcell.ColorBlack)
for x := 0; x < sl.v.width; x++ {
2016-03-19 00:40:00 +00:00
if x < Count(file) {
2016-03-17 22:20:07 +00:00
sl.v.s.SetContent(x, y, []rune(file)[x], nil, statusLineStyle)
} else {
sl.v.s.SetContent(x, y, ' ', nil, statusLineStyle)
}
}
}