]> git.lizzy.rs Git - micro.git/blob - cmd/micro/statusline.go
Rewrite gofmt and goimports as plugins
[micro.git] / cmd / micro / statusline.go
1 package main
2
3 import (
4         "strconv"
5 )
6
7 // Statusline represents the information line at the bottom
8 // of each view
9 // It gives information such as filename, whether the file has been
10 // modified, filetype, cursor location
11 type Statusline struct {
12         view *View
13 }
14
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
19
20         file := sline.view.Buf.Name
21         // If the name is empty, use 'No name'
22         if file == "" {
23                 file = "No name"
24         }
25
26         // If the buffer is dirty (has been modified) write a little '+'
27         if sline.view.Buf.IsDirty() {
28                 file += " +"
29         }
30
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)
37
38         file += " (" + lineNum + "," + columnNum + ")"
39
40         // Add the filetype
41         file += " " + sline.view.Buf.Filetype
42
43         rightText := "Ctrl-g for help "
44         if helpOpen {
45                 rightText = "Ctrl-g to close help "
46         }
47
48         statusLineStyle := defStyle.Reverse(true)
49         if style, ok := colorscheme["statusline"]; ok {
50                 statusLineStyle = style
51         }
52
53         // Maybe there is a unicode filename?
54         fileRunes := []rune(file)
55         for x := 0; x < sline.view.width; x++ {
56                 if x < len(fileRunes) {
57                         screen.SetContent(x, y, fileRunes[x], nil, statusLineStyle)
58                 } else if x >= sline.view.width-len(rightText) && x < len(rightText)+sline.view.width-len(rightText) {
59                         screen.SetContent(x, y, []rune(rightText)[x-sline.view.width+len(rightText)], nil, statusLineStyle)
60                 } else {
61                         screen.SetContent(x, y, ' ', nil, statusLineStyle)
62                 }
63         }
64 }