]> git.lizzy.rs Git - micro.git/blob - cmd/micro/help.go
Create ~/.micro if it does not exist
[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 colorscheme: loads the colorscheme stored in ~/.micro/colorschemes/'option'.micro
52         default value: 'default'
53
54 tabsize: sets the tab size to 'option'
55         default value: '4'
56
57 syntax: turns syntax on or off
58         default value: 'on'
59 `
60
61 // DisplayHelp displays the help txt
62 // It blocks the main loop
63 func DisplayHelp() {
64         topline := 0
65         _, height := screen.Size()
66         screen.HideCursor()
67         totalLines := strings.Split(helpTxt, "\n")
68         for {
69                 screen.Clear()
70
71                 lineEnd := topline + height
72                 if lineEnd > len(totalLines) {
73                         lineEnd = len(totalLines)
74                 }
75                 lines := totalLines[topline:lineEnd]
76                 for y, line := range lines {
77                         for x, ch := range line {
78                                 st := defStyle
79                                 screen.SetContent(x, y, ch, nil, st)
80                         }
81                 }
82
83                 screen.Show()
84
85                 event := screen.PollEvent()
86                 switch e := event.(type) {
87                 case *tcell.EventResize:
88                         _, height = e.Size()
89                 case *tcell.EventKey:
90                         switch e.Key() {
91                         case tcell.KeyUp:
92                                 if topline > 0 {
93                                         topline--
94                                 }
95                         case tcell.KeyDown:
96                                 if topline < len(totalLines)-height {
97                                         topline++
98                                 }
99                         case tcell.KeyCtrlQ, tcell.KeyCtrlW, tcell.KeyEscape, tcell.KeyCtrlC:
100                                 return
101                         }
102                 }
103         }
104 }