-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmenu.go
More file actions
105 lines (95 loc) · 3.09 KB
/
menu.go
File metadata and controls
105 lines (95 loc) · 3.09 KB
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
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
// inputHandler This is a basic input loop that listens for
// a few words that correspond to functions in the app. When
// a command isn't understood, it displays the help menu and
// returns to listening to input.
func inputHandler(keyCollection *ED25519Keys) {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("\n\n%v%v%v\n", white+"Type '", brightgreen+"menu", white+"' to view a list of commands")
for {
fmt.Print(brightcyan + "$> " + nc)
text, _ := reader.ReadString('\n')
text = strings.TrimSpace(text)
if strings.Compare("help", text) == 0 {
menu()
} else if strings.Compare("?", text) == 0 {
menu()
} else if strings.Compare("pubkey", text) == 0 {
fmt.Printf(brightcyan + "Pubkey: ")
fmt.Printf(cyan+"%s\n", keyCollection.publicKey)
} else if strings.Compare("menu", text) == 0 {
menu()
} else if strings.Compare("version", text) == 0 {
menuVersion()
} else if strings.Compare("license", text) == 0 {
printLicense()
} else if strings.Compare("exit", text) == 0 {
os.Exit(0)
} else if strings.HasPrefix(text, "connect") {
menuConnectChannel(text, keyCollection)
} else if strings.HasPrefix(text, "send") {
sendBody := strings.TrimPrefix(text, "send ")
cmdString := strings.Split(sendBody, " ")
// conn := requestSocket(cmdString[0], "1")
handShake(conn, keyCollection.publicKey)
certFile := configHostsDir + "/" + cmdString[0] + ".cert"
sendV1Transaction(cmdString[1], keyCollection.publicKey, cmdString[0], certFile, conn)
}
}
}
func menuConnectChannel(text string, keyCollection *ED25519Keys) {
address := strings.TrimPrefix(text, "connect ")
if !strings.Contains(address, ":") {
fmt.Printf("\nDid you forget to include the port?\n")
}
if strings.Contains(address, ":") {
var domain = strings.Split(address, ":")
var ktxCert = configHostsDir + "/" + domain[0] + ".cert"
if !fileExists(ktxCert) {
fmt.Printf(brightcyan+"\nConnecting:"+white+" %s", address)
conn = joinChannel(address, keyCollection.publicKey, keyCollection.signedKey, "", keyCollection)
} else if fileExists(ktxCert) {
isFirstTime = false
conn = joinChannel(address, keyCollection.publicKey, keyCollection.signedKey, ktxCert, keyCollection)
}
}
}
func menu() {
menuOptions := []string{"GENERAL_OPTIONS"}
menuData := map[string][][]string{
"GENERAL_OPTIONS": {
{
white + "For more help ->" + brightcyan + " https://github.com/karai" + brightwhite,
"",
"connect <ip.ip.ip.ip:port> \t\t Connects to Karai Coordinator",
"send <ip.ip.ip.ip:port> <file.json> \t Send tx with contents of <file.json> to channel",
"",
"version \t\t\t\t Displays version",
"license \t\t\t\t Displays license",
"exit \t\t\t\t\t Quit immediately",
"",
},
},
}
for _, opt := range menuOptions {
fmt.Printf(brightgreen + "\n" + opt)
for menuOptionColor, options := range menuData[opt] {
switch menuOptionColor {
case 0:
fmt.Printf(brightwhite)
case 1:
fmt.Printf(brightblack)
}
for _, message := range options {
fmt.Printf("\n" + message)
}
}
}
fmt.Printf("\n")
}