/
help.go
103 lines (84 loc) · 3.03 KB
/
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
package views
import (
"bufio"
"fmt"
"strings"
"github.com/jroimartin/gocui"
"github.com/lawrencegripper/azbrowse/internal/pkg/style"
)
// DrawHelp renders the popup help view
func DrawHelp(keyBindings map[string]string, v *gocui.View) {
for k, v := range keyBindings {
keyBindings[k] = strings.ToUpper(v)
}
view := fmt.Sprintf(`
--> PRESS %s TO CLOSE THIS AND CONTINUE. YOU CAN OPEN IT AGAIN WITH %s AT ANY TIME. <--
_ ___
/_\ __| _ )_ _ _____ __ _____ ___
/ _ \ |_ / _ \ '_/ _ \ V V (_-</ -_)
/_/ \_\/__|___/_| \___/\_/\_//__/\___|
Interactive CLI for browsing Azure resources
# Navigation
| Action | Key(s)
| -------------------------| --------------------
| Select resource | %s / %s
| Select menu/JSON | %s / %s
| Go back | %s
| Expand/View resource | %s
| Refresh | %s
| Show this help page | %s
# Operations
| Action | Key(s)
| -------------------------| --------------------
| Toggle browse JSON | %s
| Toggle fullscreen | %s
| Open Azure portal | %s
| Delete resource | %s
| Save JSON to clipboard | %s
| View actions for resource| %s
| Edit Resource | %s
For bugs, issue or to contribute visit: https://github.com/lawrencegripper/azbrowse
# Status Icons
Deleting: ☠ Failed: ⛈ Updating: ⟳ Resuming/Starting: ⛅ Provisioning: ⌛
Creating\Preparing: 🏗 Scaling: ⚖ Suspended/Suspending: ⛔ Succeeded: 🌣
--> PRESS %s TO CLOSE THIS AND CONTINUE. YOU CAN OPEN IT AGAIN WITH %s AT ANY TIME. <--
`, keyBindings["help"],
keyBindings["help"],
keyBindings["listup"],
keyBindings["listdown"],
keyBindings["itemleft"],
keyBindings["listright"],
keyBindings["listback"],
keyBindings["listexpand"],
keyBindings["listrefresh"],
keyBindings["help"],
keyBindings["listedit"],
keyBindings["fullscreen"],
keyBindings["listopen"],
keyBindings["listdelete"],
keyBindings["copy"],
keyBindings["listactions"],
keyBindings["listupdate"],
keyBindings["help"],
keyBindings["help"])
maxWidth, maxHeight := v.Size()
paddedView := ""
lineCount := 0
scanner := bufio.NewScanner(strings.NewReader(view))
for scanner.Scan() {
line := scanner.Text()
rightPadLen := maxWidth - len(line)
pad := ""
if rightPadLen > 0 {
pad = strings.Repeat(" ", rightPadLen)
}
paddedView = fmt.Sprintf("%s%s%s\n", paddedView, line, pad)
lineCount++
}
bottomPadLen := maxHeight - lineCount
for i := 0; i < bottomPadLen; i++ {
pad := strings.Repeat(" ", maxWidth)
paddedView = fmt.Sprintf("%s%s\n", paddedView, pad)
}
fmt.Fprint(v, style.Header(paddedView))
}