7 // Statusline represents the information line at the bottom
9 // It gives information such as filename, whether the file has been
10 // modified, filetype, cursor location
11 type Statusline struct {
15 // Display draws the statusline to the screen
16 func (sline *Statusline) Display() {
17 // We'll draw the line at the lowest line in the view
18 y := sline.view.height
20 file := sline.view.buf.name
21 // If the name is empty, use 'No name'
26 // If the buffer is dirty (has been modified) write a little '+'
27 if sline.view.buf.IsDirty() {
31 // Add one to cursor.x and cursor.y because (0,0) is the top left,
32 // but users will be used to (1,1) (first line,first column)
33 // We use GetVisualX() here because otherwise we get the column number in runes
34 // so a '\t' is only 1, when it should be tabSize
35 columnNum := strconv.Itoa(sline.view.cursor.GetVisualX() + 1)
36 lineNum := strconv.Itoa(sline.view.cursor.y + 1)
38 file += " (" + lineNum + "," + columnNum + ")"
41 file += " " + sline.view.buf.filetype
43 centerText := "Press Ctrl-g for help"
45 statusLineStyle := defStyle.Reverse(true)
46 if style, ok := colorscheme["statusline"]; ok {
47 statusLineStyle = style
50 // Maybe there is a unicode filename?
51 fileRunes := []rune(file)
52 for x := 0; x < sline.view.width; x++ {
53 if x < len(fileRunes) {
54 screen.SetContent(x, y, fileRunes[x], nil, statusLineStyle)
55 } else if x >= sline.view.width/2-len(centerText)/2 && x < len(centerText)+sline.view.width/2-len(centerText)/2 {
56 screen.SetContent(x, y, []rune(centerText)[x-sline.view.width/2+len(centerText)/2], nil, statusLineStyle)
58 screen.SetContent(x, y, ' ', nil, statusLineStyle)