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 + sline.view.y
20 file := sline.view.Buf.GetName()
22 // If the buffer is dirty (has been modified) write a little '+'
23 if sline.view.Buf.IsModified {
27 // Add one to cursor.x and cursor.y because (0,0) is the top left,
28 // but users will be used to (1,1) (first line,first column)
29 // We use GetVisualX() here because otherwise we get the column number in runes
30 // so a '\t' is only 1, when it should be tabSize
31 columnNum := strconv.Itoa(sline.view.Cursor.GetVisualX() + 1)
32 lineNum := strconv.Itoa(sline.view.Cursor.Y + 1)
34 file += " (" + lineNum + "," + columnNum + ")"
37 file += " " + sline.view.Buf.FileType()
39 file += " " + sline.view.Buf.Settings["fileformat"].(string)
42 if len(helpBinding) > 0 {
43 rightText = helpBinding + " for help "
44 if sline.view.Type == vtHelp {
45 rightText = helpBinding + " to close help "
49 statusLineStyle := defStyle.Reverse(true)
50 if style, ok := colorscheme["statusline"]; ok {
51 statusLineStyle = style
54 // Maybe there is a unicode filename?
55 fileRunes := []rune(file)
58 screen.SetContent(viewX, y, ' ', nil, statusLineStyle)
61 for x := 0; x < sline.view.Width; x++ {
62 if x < len(fileRunes) {
63 screen.SetContent(viewX+x, y, fileRunes[x], nil, statusLineStyle)
64 } else if x >= sline.view.Width-len(rightText) && x < len(rightText)+sline.view.Width-len(rightText) {
65 screen.SetContent(viewX+x, y, []rune(rightText)[x-sline.view.Width+len(rightText)], nil, statusLineStyle)
67 screen.SetContent(viewX+x, y, ' ', nil, statusLineStyle)