This repository has been archived by the owner on Jun 13, 2022. It is now read-only.
forked from rgburke/grv
/
config_command_help.go
503 lines (459 loc) · 19.4 KB
/
config_command_help.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
package main
import (
"strings"
)
// GenerateSetCommandHelpSections generates help documentation for the set command
func GenerateSetCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "set", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The set command allows configuration variables to be set. It has the form:"},
{},
{text: "set variable value", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "For example, to set the tab width to tab width to 4, the currently active theme to \"mytheme\" and enable mouse support:"},
{},
{text: "set tabwidth 4", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "set theme mytheme", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "set mouse true", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "GRV currently has the following themes available:"},
{},
{text: " - solarized"},
{text: " - classic"},
{},
{text: "The solarized theme is the default theme for GRV and does not respect the terminals colour palette."},
{text: "The classic theme respects the terminals colour palette."},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateThemeCommandHelpSections generates help documentation for the theme command
func GenerateThemeCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "theme", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The theme command allows a custom theme to be defined."},
{text: "This theme can then be activated using the theme config variable described above."},
{text: "The form of the theme command is:"},
{},
{text: "theme --name [ThemeName] --component [ComponentId] --bgcolor [BackgroundColor] --fgcolor [ForegroundColor]", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: " - ThemeName: The name of the theme to be created/updated."},
{text: " - ComponentId: The Id of the screen component (the part of the display to change)."},
{text: " - BackgroundColor: The background color."},
{text: " - ForegroundColor: The foreground color."},
{},
{text: "Using a sequence of theme commands it is possible to define a theme."},
{text: "For example, to define a new theme \"mytheme\" and set it as the active theme:"},
{},
{text: "theme --name mytheme --component CommitView.Date --bgcolor None --fgcolor Red", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "theme --name mytheme --component RefView.Tag --bgcolor Blue --fgcolor 36", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "theme --name mytheme --component StatusBarView.Normal --bgcolor None --fgcolor f14a98", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "set theme mytheme", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "GRV supports 256 colors (when available). Provided colors will be mapped to the nearest available color."},
{text: "The allowed color values are:"},
{},
{text: "System colors:"},
{},
{text: "None", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "Black", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "Red", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "Green", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "Yellow", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "Blue", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "Magenta", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "Cyan", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "White", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "Terminal Color Numbers:"},
{},
{text: "0 - 255", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "Hex Colors:"},
{},
{text: "000000 - ffffff", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "The set of screen components that can be customised is:"},
{},
}
var prevPrefix string
for _, themeComponent := range ThemeComponentNames() {
prefix := strings.Split(themeComponent, ".")[0]
if prevPrefix != "" && prevPrefix != prefix {
description = append(description, HelpSectionText{themeComponentID: CmpHelpViewSectionCodeBlock})
}
prevPrefix = prefix
description = append(description, HelpSectionText{text: themeComponent, themeComponentID: CmpHelpViewSectionCodeBlock})
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateMapCommandHelpSections generates help documentation for the map command
func GenerateMapCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "map", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The map command allows a key sequence to be mapped to an action, another key sequence or a shell command for a specified view."},
{text: "The form of the map command is:"},
{},
{text: "map view fromkeys tokeys", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "For example, to map the key 'a' to the keys 'gg' in the Ref View:"},
{},
{text: "map RefView a gg", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "When pressing 'a' in the Ref View, the first line would then become the selected line, as 'gg' moves the cursor to the first line."},
{text: "All is a valid view argument when a binding should apply to all views."},
{},
{text: "GRV also has a text representation of actions that are independent of key bindings."},
{text: "For example, the following commands can be used to make the <Up> key move a line down and the <Down> key move a line up:"},
{},
{text: "map All <Up> <grv-next-line>", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "map All <Down> <grv-prev-line>", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "The map command also allows a key sequence to be mapped directly to a shell command."},
{text: "Prefix a shell command with the '!' character. For example, to map the key 'a' to the shell command 'ls -lh':"},
{},
{text: "map All a !ls -lh", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "The set of actions available is described in the key binding tables above."},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateUnmapCommandHelpSections generates help documentation for the unmap command
func GenerateUnmapCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "unmap", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The unmap command removes any defined key binding for a key sequence in the specified view."},
{text: "The form of the unmap command is:"},
{},
{text: "unmap view fromkeys", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "For example, to unmap the key 'c' in the Ref View:"},
{},
{text: "unmap RefView c", themeComponentID: CmpHelpViewSectionCodeBlock},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateQuitCommandHelpSections generates help documentation for the quit command
func GenerateQuitCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "q", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The quit command is used to exit GRV and can be used with the following keys:"},
{},
{text: ":q<Enter>", themeComponentID: CmpHelpViewSectionCodeBlock},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateAddTabCommandHelpSections generates help documentation for the addtab command
func GenerateAddTabCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "addtab", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The addtab command creates a new named empty tab and switches to this new tab."},
{text: "The format of the command is:"},
{},
{text: "addtab tabname", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "For example, to add a new tab titled \"mycustomtab\" the following command can be used:"},
{},
{text: "addtab mycustomtab", themeComponentID: CmpHelpViewSectionCodeBlock},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateRmTabCommandHelpSections generates help documentation for the rmtab command
func GenerateRmTabCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "rmtab", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The rmtab removes the currently active tab. If the tab removed is the last tab then GRV will exit."},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateAddViewCommandHelpSections generates help documentation for the addview command
func GenerateAddViewCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "addview", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The addview command allows a view to be added to the currently active tab."},
{text: "The form of the command is:"},
{},
{text: "addview view viewargs...", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "Each view accepts a different set of arguments. This is described in the table below:"},
}
helpSections = append(helpSections, &HelpSection{
description: description,
})
helpSections = append(helpSections, GenerateWindowViewFactoryHelpSection(config))
description = []HelpSectionText{
{text: "Examples usages for each view are given below:"},
{},
{text: "addview CommitView origin/master", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "addview DiffView 4882ca9044661b49a26ae03ceb1be3a70d00c6a2", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "addview GitStatusView", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "addview RefView", themeComponentID: CmpHelpViewSectionCodeBlock},
}
helpSections = append(helpSections, &HelpSection{
description: description,
})
return
}
// GenerateVSplitCommandHelpSections generates help documentation for the vsplit command
func GenerateVSplitCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "vsplit", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The vsplit command creates a vertical split between the currently selected view and the view specified in the command."},
{text: "The form of the command is:"},
{},
{text: "vsplit view viewargs...", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "For example, to create a vertical split between the currently selected view and a CommitView displaying commits for master:"},
{},
{text: "vsplit CommitView master", themeComponentID: CmpHelpViewSectionCodeBlock},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateHSplitCommandHelpSections generates help documentation for the hsplit command
func GenerateHSplitCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "hsplit", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The hsplit command creates a horizontal split between the currently selected view and the view specified in the command."},
{text: "The form of the command is:"},
{},
{text: "hsplit view viewargs...", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "For example, to create a horizontal split between the currently selected view and a RefView:"},
{},
{text: "hsplit RefView", themeComponentID: CmpHelpViewSectionCodeBlock},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateSplitCommandHelpSections generates help documentation for the split command
func GenerateSplitCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "split", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The split command is similar to the vsplit and hsplit commands."},
{text: "It creates either a new vsplit or hsplit determined by the current dimensions of the active view."},
{text: "The form of the command is:"},
{},
{text: "split view viewargs...", themeComponentID: CmpHelpViewSectionCodeBlock},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateGitCommandHelpSections generates help documentation for the git command
func GenerateGitCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "git", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The git command is an alias to the git cli command."},
{text: "It allows a non-interactive git command to run without having to leave GRV."},
{text: "A pop-up window displays the output of the command."},
{text: "For example, to run 'git status' from within GRV use the following key sequence"},
{},
{text: ":git status", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "Only non-interactive git commands (i.e. those that require no user input) can be run using the git command."},
{text: "For interactive git commands the giti command can be used."},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateGitiCommandHelpSections generates help documentation for the giti command
func GenerateGitiCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "giti", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The git command is an alias to the git cli command."},
{text: "It allows an interactive git command (i.e. those that require user input) to be run without having to leave GRV."},
{text: "The command is executed in the controlling terminal and GRV is resumed on command completion."},
{text: "For example, to run 'git rebase -i HEAD~2' use the following key sequence:"},
{},
{text: ":giti rebase -i HEAD~2", themeComponentID: CmpHelpViewSectionCodeBlock},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateHelpCommandHelpSections generates help documentation for the help command
func GenerateHelpCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "help", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The help command opens a tab containing documentation for GRV."},
{text: "A search term can be provided as an argument. For example:"},
{},
{text: "help vsplit", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "will display the section for the command vsplit in the help tab"},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateDefCommandHelpSections generates help documentation for the def command
func GenerateDefCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "def", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The def command allows a custom GRV command to be defined. It has the form:"},
{},
{text: "def NAME {", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "\tBODY", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "}", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "where NAME is the name of the new command and BODY is a sequence of commands to execute."},
{text: "For example, to define a command \"maintab\" to open a new tab containing the CommitView for master:"},
{},
{text: "def maintab {", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "\taddtab Main", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "\taddview CommitView master", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "}", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "This command can be invoked at the command prompt with:"},
{},
{text: ":maintab", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "The command body can contain argument placeholders that will be substituted on invocation."},
{text: "Argument placeholders have the form $n or ${n} where n is an integer greater than zero corresponding to the argument to substitute."},
{text: "For example, the \"maintab\" command defined earlier can be altered to accept the branch in as an argument:"},
{},
{text: "def maintab {", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "\taddtab Main", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "\taddview CommitView $1", themeComponentID: CmpHelpViewSectionCodeBlock},
{text: "}", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "To invoke this command for the branch \"feature-branch\" and open a new tab containing the commit view for this branch:"},
{},
{text: ":maintab feature-branch", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "All arguments can be substituted using the placeholder $@ or ${@}"},
{text: "For example, the following command acts as an alias for the vsplit command:"},
{},
{text: "def vs { vsplit $@ }", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "and can be invoked with:"},
{},
{text: ":vs CommitView master", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "Argument placeholders can be escaped by prepending a dollar sign."},
{text: "For example, to specify the literal string $1 in a command body specify $$1."},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateUndefCommandHelpSections generates help documentation for the addtab command
func GenerateUndefCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "undef", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The undef command removes a user defined command."},
{text: "The format of the command is:"},
{},
{text: "undef commandname", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "For example, to undefine a comamnd \"mycustomcommand\" the following can be used:"},
{},
{text: "undef mycustomcommand", themeComponentID: CmpHelpViewSectionCodeBlock},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateEvalKeysCommandHelpSections generates help documentation for the addtab command
func GenerateEvalKeysCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "evalkeys", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The evalkeys command executes the provided key string sequence."},
{text: "The format of the command is:"},
{},
{text: "evalkeys keys", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "For example, running the following will switch to the next tab:"},
{},
{text: "evalkeys <grv-next-tab>", themeComponentID: CmpHelpViewSectionCodeBlock},
}
return []*HelpSection{
{
description: description,
},
}
}
// GenerateSleepCommandHelpSections generates help documentation for the addtab command
func GenerateSleepCommandHelpSections(config Config) (helpSections []*HelpSection) {
description := []HelpSectionText{
{text: "sleep", themeComponentID: CmpHelpViewSectionSubTitle},
{},
{text: "The sleep command causes grv to pause execution for the provided number of seconds."},
{text: "The format of the command is:"},
{},
{text: "sleep seconds", themeComponentID: CmpHelpViewSectionCodeBlock},
{},
{text: "For example, running the following will pause execution for 0.5 seconds:"},
{},
{text: "sleep 0.5", themeComponentID: CmpHelpViewSectionCodeBlock},
}
return []*HelpSection{
{
description: description,
},
}
}