-
Notifications
You must be signed in to change notification settings - Fork 1
/
usage.go
114 lines (99 loc) · 3.61 KB
/
usage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"fmt"
"strings"
"github.com/charmbracelet/bubbles/key"
)
func usage() string {
usage := `
%s (%s) is a terminal filesystem explorer built for interactive ls workflows.
Useful key commands are listed in the status bar.
`
return fmt.Sprintf(usage,
name, getVersion(),
)
}
func commands() string {
pad := 12
usageKeyLine := func(text string, key key.Binding) string {
keyStr := keyString(key)
textParts := strings.Split(text, "\n")
s := []string{
fmt.Sprintf("\t\"%s\":%s%s", keyStr, strings.Repeat(" ", pad-len(keyStr)), textParts[0]),
}
for _, textPart := range textParts[1:] {
s = append(s, fmt.Sprintf("\t %s%s", strings.Repeat(" ", pad), textPart))
}
return strings.Join(s, "\n")
}
usage := `
------------
| Commands |
------------
Arrow keys are used to move the cursor.
Vim navigation is available using "h" (left), "j" (down) "k" (up), and "l" (right).
%s
`
cmds := []string{
usageKeyLine("navigates into the directory or returns the\npath to the entry under the cursor", keySelect),
usageKeyLine("navigates back to the previous directory", keyBack),
"",
usageKeyLine("returns the path(s) to the current entry or all marked entries", keyReturnSelected),
usageKeyLine("returns the path to the current directory", keyReturnDirectory),
"",
usageKeyLine("enters search mode (insert into the path)", keyModeSearch),
usageKeyLine("enters debug mode (view error details)", keyModeDebug),
usageKeyLine("enters help mode", keyModeHelp),
usageKeyLine("switches back to normal mode or clears search filter in normal mode", keyEsc),
"",
usageKeyLine("(un)marks an entry for multiselect return", keyMark),
usageKeyLine("(un)marks all entries for multiselect return", keyMarkAll),
"",
usageKeyLine("toggles showing hidden files (ls -a)", keyToggleHidden),
usageKeyLine("toggles listing full file information (ls -l)", keyToggleList),
usageKeyLine("toggles following symlinks", keyToggleFollowSymlink),
"",
usageKeyLine("dismisses errors", keyDismissError),
usageKeyLine("quits the application with no return value", keyQuit),
}
return fmt.Sprintf(usage, strings.Join(cmds, "\n"))
}
func flags() string {
pad := 25
usageFlagLine := func(text string, flags ...string) string {
flagStr := strings.Join(flags, ", ")
textParts := strings.Split(text, "\n")
s := []string{
fmt.Sprintf("\t%s:%s%s", flagStr, strings.Repeat(" ", pad-len(flagStr)), textParts[0]),
}
for _, textPart := range textParts[1:] {
s = append(s, fmt.Sprintf("\t %s%s", strings.Repeat(" ", pad), textPart))
}
return strings.Join(s, "\n")
}
usage := `
---------
| Flags |
---------
%s
`
flags := []string{
usageFlagLine("display help", flagHelp, flagHelpShort, flagHelpShortCaps),
usageFlagLine("display version", flagVersion, flagVersionShort),
"",
usageFlagLine("start in search mode", flagSearch, flagSearchShort),
"",
usageFlagLine("return output suitable for pipe and subshell usage", flagPipe),
"",
usageFlagLine("toggle on following symlinks at startup", flagFollowSymlinks, flagFollowSymlinksShort),
usageFlagLine("toggle on showing hidden files at startup", flagHidden, flagHiddenShort),
usageFlagLine("toggle on list mode at startup", flagList, flagListShort),
"",
usageFlagLine("toggle off color output", flagNoColor),
usageFlagLine("toggle off bottom status bar menu", flagNoStatusBar),
usageFlagLine("toggle off trailing annotators", flagNoTrailing),
"",
usageFlagLine("remap the escape key to the following value, using\nrepeated values to require multiple presses", flagRemapEsc),
}
return fmt.Sprintf(usage, strings.Join(flags, "\n"))
}