]> git.lizzy.rs Git - micro.git/blob - cmd/micro/help.go
Prevent panic if mouse y coordinate is below 0
[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-q to quit 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-h:   Open help
30
31 Ctrl-u:   Half page up
32 Ctrl-d:   Half page down
33 PageUp:   Page up
34 PageDown: Page down
35
36 Ctrl-e:   Execute a command
37
38 Possible commands:
39
40 'quit': Quits micro
41 'save': saves the current buffer
42
43 'replace "search" "value"': This will replace 'search' with 'value'.
44 Note that 'search' must be a valid regex.  If one of the arguments
45 does not have any spaces in it, you may omit the quotes.
46
47 'set option value': sets the option to value. Please see the next section for a list of options you can set
48
49 Micro options:
50
51 Configuration directory:
52
53 Micro uses the $XDG_CONFIG_HOME/micro as the configuration directory. As per the XDG spec,
54 if $XDG_CONFIG_HOME is not set, ~/.config/micro is used as the config directory.
55
56 colorscheme: loads the colorscheme stored in $(configDir)/colorschemes/'option'.micro
57         default value: 'default'
58         Note that the default colorschemes (default, solarized, and solarized-tc) are not located in configDir,
59         because they are embedded in the micro binary
60
61 tabsize: sets the tab size to 'option'
62         default value: '4'
63
64 syntax: turns syntax on or off
65         default value: 'on'
66 `
67
68 // DisplayHelp displays the help txt
69 // It blocks the main loop
70 func DisplayHelp() {
71         topline := 0
72         _, height := screen.Size()
73         screen.HideCursor()
74         totalLines := strings.Split(helpTxt, "\n")
75         for {
76                 screen.Clear()
77
78                 lineEnd := topline + height
79                 if lineEnd > len(totalLines) {
80                         lineEnd = len(totalLines)
81                 }
82                 lines := totalLines[topline:lineEnd]
83                 for y, line := range lines {
84                         for x, ch := range line {
85                                 st := defStyle
86                                 screen.SetContent(x, y, ch, nil, st)
87                         }
88                 }
89
90                 screen.Show()
91
92                 event := screen.PollEvent()
93                 switch e := event.(type) {
94                 case *tcell.EventResize:
95                         _, height = e.Size()
96                 case *tcell.EventKey:
97                         switch e.Key() {
98                         case tcell.KeyUp:
99                                 if topline > 0 {
100                                         topline--
101                                 }
102                         case tcell.KeyDown:
103                                 if topline < len(totalLines)-height {
104                                         topline++
105                                 }
106                         case tcell.KeyCtrlQ, tcell.KeyCtrlW, tcell.KeyEscape, tcell.KeyCtrlC:
107                                 return
108                         }
109                 }
110         }
111 }