]> git.lizzy.rs Git - micro.git/blob - cmd/micro/statusline.go
Add hidehelp option
[micro.git] / cmd / micro / statusline.go
1 package main
2
3 import (
4         "path"
5         "strconv"
6 )
7
8 // Statusline represents the information line at the bottom
9 // of each view
10 // It gives information such as filename, whether the file has been
11 // modified, filetype, cursor location
12 type Statusline struct {
13         view *View
14 }
15
16 // Display draws the statusline to the screen
17 func (sline *Statusline) Display() {
18         if messenger.hasPrompt && !GetGlobalOption("infobar").(bool) {
19                 return
20         }
21
22         // We'll draw the line at the lowest line in the view
23         y := sline.view.Height + sline.view.y
24
25         file := sline.view.Buf.GetName()
26         if sline.view.Buf.Settings["basename"].(bool) {
27                 file = path.Base(file)
28         }
29
30         // If the buffer is dirty (has been modified) write a little '+'
31         if sline.view.Buf.Modified() {
32                 file += " +"
33         }
34
35         // Add one to cursor.x and cursor.y because (0,0) is the top left,
36         // but users will be used to (1,1) (first line,first column)
37         // We use GetVisualX() here because otherwise we get the column number in runes
38         // so a '\t' is only 1, when it should be tabSize
39         columnNum := strconv.Itoa(sline.view.Cursor.GetVisualX() + 1)
40         lineNum := strconv.Itoa(sline.view.Cursor.Y + 1)
41
42         file += " (" + lineNum + "," + columnNum + ")"
43
44         // Add the filetype
45         file += " " + sline.view.Buf.FileType()
46
47         file += " " + sline.view.Buf.Settings["fileformat"].(string)
48
49         rightText := ""
50         if !sline.view.Buf.Settings["hidehelp"].(bool) {
51                 if len(kmenuBinding) > 0 {
52                         if globalSettings["keymenu"].(bool) {
53                                 rightText += kmenuBinding + ": hide bindings"
54                         } else {
55                                 rightText += kmenuBinding + ": show bindings"
56                         }
57                 }
58                 if len(helpBinding) > 0 {
59                         if len(kmenuBinding) > 0 {
60                                 rightText += ", "
61                         }
62                         if sline.view.Type == vtHelp {
63                                 rightText += helpBinding + ": close help"
64                         } else {
65                                 rightText += helpBinding + ": open help"
66                         }
67                 }
68                 rightText += " "
69         }
70
71         statusLineStyle := defStyle.Reverse(true)
72         if style, ok := colorscheme["statusline"]; ok {
73                 statusLineStyle = style
74         }
75
76         // Maybe there is a unicode filename?
77         fileRunes := []rune(file)
78
79         if sline.view.Type == vtTerm {
80                 fileRunes = []rune(sline.view.term.title)
81                 rightText = ""
82         }
83
84         viewX := sline.view.x
85         if viewX != 0 {
86                 screen.SetContent(viewX, y, ' ', nil, statusLineStyle)
87                 viewX++
88         }
89         for x := 0; x < sline.view.Width; x++ {
90                 if x < len(fileRunes) {
91                         screen.SetContent(viewX+x, y, fileRunes[x], nil, statusLineStyle)
92                 } else if x >= sline.view.Width-len(rightText) && x < len(rightText)+sline.view.Width-len(rightText) {
93                         screen.SetContent(viewX+x, y, []rune(rightText)[x-sline.view.Width+len(rightText)], nil, statusLineStyle)
94                 } else {
95                         screen.SetContent(viewX+x, y, ' ', nil, statusLineStyle)
96                 }
97         }
98 }