]> git.lizzy.rs Git - micro.git/blob - cmd/micro/help.go
Merge pull request #44 from aerth/fork1
[micro.git] / cmd / micro / help.go
1 package main
2
3 import (
4         "github.com/gdamore/tcell"
5         "strings"
6 )
7
8 const helpTxt = `Press Ctrl-g to close help
9
10 Micro keybindings:
11
12 Ctrl-q:   Quit
13 Ctrl-s:   Save
14 Ctrl-o:   Open file
15
16 Ctrl-z:   Undo
17 Ctrl-y:   Redo
18
19 Ctrl-f:   Find
20 Ctrl-n:   Find next
21 Ctrl-p:   Find previous
22
23 Ctrl-a:   Select all
24
25 Ctrl-c:   Copy
26 Ctrl-x:   Cut
27 Ctrl-v:   Paste
28
29 Ctrl-g:   Open this help screen
30
31 Ctrl-u:   Half page up
32 Ctrl-d:   Half page down
33 PageUp:   Page up
34 PageDown: Page down
35
36 Home:     Go to beginning
37 End:      Go to end
38
39 Ctrl-e:   Execute a command
40
41 Possible commands:
42
43 'quit': Quits micro
44 'save': saves the current buffer
45
46 'replace "search" "value"': This will replace 'search' with 'value'.
47 Note that 'search' must be a valid regex.  If one of the arguments
48 does not have any spaces in it, you may omit the quotes.
49
50 'set option value': sets the option to value. Please see the next section for a list of options you can set
51
52 Micro options:
53
54 Configuration directory:
55
56 Micro uses the $XDG_CONFIG_HOME/micro as the configuration directory. As per the XDG spec,
57 if $XDG_CONFIG_HOME is not set, ~/.config/micro is used as the config directory.
58
59 colorscheme: loads the colorscheme stored in $(configDir)/colorschemes/'option'.micro
60         default value: 'default'
61         Note that the default colorschemes (default, solarized, and solarized-tc) are not located in configDir,
62         because they are embedded in the micro binary
63
64 tabsize: sets the tab size to 'option'
65         default value: '4'
66
67 syntax: turns syntax on or off
68         default value: 'on'
69
70 tabsToSpaces: use spaces instead of tabs
71         default value: 'off'
72 `
73
74 // DisplayHelp displays the help txt
75 // It blocks the main loop
76 func DisplayHelp() {
77         topline := 0
78         _, height := screen.Size()
79         screen.HideCursor()
80         totalLines := strings.Split(helpTxt, "\n")
81         for {
82                 screen.Clear()
83
84                 lineEnd := topline + height
85                 if lineEnd > len(totalLines) {
86                         lineEnd = len(totalLines)
87                 }
88                 lines := totalLines[topline:lineEnd]
89                 for y, line := range lines {
90                         for x, ch := range line {
91                                 st := defStyle
92                                 screen.SetContent(x, y, ch, nil, st)
93                         }
94                 }
95
96                 screen.Show()
97
98                 event := screen.PollEvent()
99                 switch e := event.(type) {
100                 case *tcell.EventResize:
101                         _, height = e.Size()
102                 case *tcell.EventKey:
103                         switch e.Key() {
104                         case tcell.KeyUp:
105                                 if topline > 0 {
106                                         topline--
107                                 }
108                         case tcell.KeyDown:
109                                 if topline < len(totalLines)-height {
110                                         topline++
111                                 }
112                         case tcell.KeyCtrlQ, tcell.KeyCtrlW, tcell.KeyEscape, tcell.KeyCtrlC:
113                                 return
114                         }
115                 }
116         }
117 }