@@ -2,6 +2,8 @@ package interactive
22
33import (
44 "fmt"
5+ "os"
6+ "strings"
57
68 "github.com/c-bata/go-prompt"
79 "github.com/koinos/koinos-cli-wallet/internal/wallet"
@@ -13,6 +15,12 @@ type KoinosPrompt struct {
1315 execEnv * wallet.ExecutionEnvironment
1416 gPrompt * prompt.Prompt
1517 commandSuggestions []prompt.Suggest
18+ unicodeSupport bool
19+
20+ onlineDisplay string
21+ offlineDisplay string
22+ openDisplay string
23+ closeDisplay string
1624}
1725
1826// NewKoinosPrompt creates a new interactive prompt object
@@ -32,20 +40,37 @@ func NewKoinosPrompt(parser *wallet.CommandParser, execEnv *wallet.ExecutionEnvi
3240 kp .commandSuggestions = append (kp .commandSuggestions , prompt.Suggest {Text : cmd .Name , Description : cmd .Description })
3341 }
3442
43+ // Check for terminal unicode support
44+ lang := strings .ToUpper (os .Getenv ("LANG" ))
45+ kp .unicodeSupport = strings .Contains (lang , "UTF" )
46+
47+ // Setup status characters
48+ if kp .unicodeSupport {
49+ kp .onlineDisplay = "🟢"
50+ kp .offlineDisplay = "🔴"
51+ kp .closeDisplay = "🔐"
52+ kp .openDisplay = "🔓"
53+ } else {
54+ kp .onlineDisplay = "(online)"
55+ kp .offlineDisplay = "(offline)"
56+ kp .closeDisplay = "(locked)"
57+ kp .openDisplay = "(unlocked)"
58+ }
59+
3560 return kp
3661}
3762
3863func (kp * KoinosPrompt ) changeLivePrefix () (string , bool ) {
3964 // Calculate online status
40- onlineStatus := "🔴"
65+ onlineStatus := kp . offlineDisplay
4166 if kp .execEnv .IsOnline () {
42- onlineStatus = "🟢"
67+ onlineStatus = kp . onlineDisplay
4368 }
4469
4570 // Calculate wallet status
46- walletStatus := "🔐"
71+ walletStatus := kp . closeDisplay
4772 if kp .execEnv .IsWalletOpen () {
48- walletStatus = "🔓"
73+ walletStatus = kp . openDisplay
4974 }
5075
5176 return fmt .Sprintf ("%s %s > " , onlineStatus , walletStatus ), true
@@ -69,7 +94,7 @@ func (kp *KoinosPrompt) executor(input string) {
6994
7095// Run runs interactive mode
7196func (kp * KoinosPrompt ) Run () {
72- fmt .Println ("Koinos CLI Wallet" )
97+ fmt .Println (fmt . Sprintf ( "Koinos CLI Wallet %s" , wallet . Version ) )
7398 fmt .Println ("Type \" list\" for a list of commands, \" help <command>\" for help on a specific command." )
7499 kp .gPrompt .Run ()
75100}
0 commit comments