generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 12
/
display.go
135 lines (114 loc) · 3.23 KB
/
display.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
package terminal
import (
"errors"
"fmt"
"os"
"os/exec"
breverrors "github.com/brevdev/brev-cli/pkg/errors"
"github.com/manifoldco/promptui"
)
type PromptSelectContent struct {
ErrorMsg string
Label string
Items []string
}
func PromptSelectInput(pc PromptSelectContent) string {
// templates := &promptui.SelectTemplates{
// Label: "{{ . }} ",
// Selected: "{{ . | green }} ",
// Active: "{{ . | cyan }} ",
// }
prompt := promptui.Select{
Label: pc.Label,
Items: pc.Items,
// Templates: templates,
}
_, result, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
os.Exit(1)
}
return result
}
func DisplayBrevLogo(t *Terminal) {
t.Vprint(" _ ")
t.Vprint(" _ ,-. / ) ")
t.Vprint(" ( `. // /-._/ / ")
t.Vprint(" `\\ \\ /(_/ / / / ")
t.Vprint(" ; `-` (_/ / / ")
t.Vprint(" | (_/ / ")
t.Vprint(" \\ / ")
t.Vprint("Welcome to ) /` ")
t.Vprint(" Brev.Dev / /` ")
}
func DisplayVSCodeInstructions(t *Terminal) {
t.Print("Run the following steps")
t.Print("")
t.Print("\t1) Install the following VSCode extension: " + t.Yellow("ms-vscode-remote.remote-ssh") + ".")
t.Print("\t2) In VS Code, open the Command Palette and type in " + t.Yellow("Remote-SSH: Connect to Host...") + "to begin.")
}
func DisplayGatewayAlreadyInstalledInstructions(t *Terminal) {
t.Print(t.Yellow("You already have JetBrains Gateway installed!"))
t.Print("Run " + t.Green("brev jetbrains") + " and then open Gateway to begin.")
}
func DisplayToolboxInstalledInstructions(t *Terminal) {
t.Print(t.Yellow("You already have JetBrains Toolbox installed!"))
t.Print("")
t.Print("\t1) Install JetBrains Gateway from Toolbox.")
t.Print("\t2) Run " + t.Green("brev jetbrains") + " and then open Gateway to begin.")
}
func InstallVSCodeExtension(t *Terminal) {
cmdd := exec.Command("which code")
output, _ := cmdd.Output()
t.Vprintf("%b", output)
_, err := cmdd.Output()
if err != nil {
t.Vprintf(t.Yellow("Please install the following VS Code extension: ms-vscode-remote.remote-ssh\n"))
} else {
install := exec.Command("code --install-extension ms-vscode-remote.remote-ssh\n")
_, err := install.Output()
if err != nil {
t.Vprintf("Please install the following VS Code extension: ms-vscode-remote.remote-ssh\n")
}
}
}
type PromptContent struct {
ErrorMsg string
Label string
Default string
AllowEmpty bool
Mask rune
}
func PromptGetInput(pc PromptContent) string {
validate := func(input string) error {
if pc.AllowEmpty {
return nil
}
if len(input) == 0 {
return breverrors.WrapAndTrace(errors.New(pc.ErrorMsg))
}
return nil
}
templates := &promptui.PromptTemplates{
Prompt: "{{ . }} ",
Valid: "{{ . | green }} ",
Invalid: "{{ . | yellow }} ",
Success: "{{ . | bold }} ",
}
prompt := promptui.Prompt{
Label: pc.Label,
Templates: templates,
Validate: validate,
Default: pc.Default,
AllowEdit: true,
}
if pc.Mask != 0 {
prompt.Mask = pc.Mask
}
result, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
os.Exit(1)
}
return result
}