5
5
"strings"
6
6
7
7
"github.com/chzyer/readline"
8
+ "github.com/fatih/color"
8
9
)
9
10
10
11
const (
@@ -25,21 +26,26 @@ func (c *CmdShell) Execute(args []string) error {
25
26
return err
26
27
}
27
28
29
+ blue := color .New (color .FgHiBlue ).SprintfFunc ()
30
+ white := color .New (color .FgWhite ).SprintfFunc ()
31
+ red := color .New (color .FgHiRed ).PrintfFunc ()
32
+
33
+ prompt := blue (initPrompt )
34
+ mlPrompt := blue (multilinePrompt )
35
+
28
36
rl , err := readline .NewEx (& readline.Config {
29
- Prompt : initPrompt ,
37
+ Prompt : prompt ,
30
38
HistoryFile : "/tmp/gitql-history" ,
31
39
DisableAutoSaveHistory : true ,
32
40
})
33
41
if err != nil {
34
42
return err
35
43
}
36
44
37
- rl .Terminal .Print (fmt .Sprint (`
38
- gitQL SHELL
39
- -----------
40
- You must end your queries with ';'
41
-
42
- ` ))
45
+ fmt .Println (" " , white ("git" )+ blue ("QL" ), "SHELL" )
46
+ fmt .Println (" -----------" )
47
+ fmt .Println ("You must end your queries with ';'" )
48
+ fmt .Println ("" )
43
49
44
50
var cmds []string
45
51
for {
@@ -53,25 +59,25 @@ You must end your queries with ';'
53
59
}
54
60
cmds = append (cmds , line )
55
61
if ! strings .HasSuffix (line , ";" ) {
56
- rl .SetPrompt (multilinePrompt )
62
+ rl .SetPrompt (mlPrompt )
57
63
continue
58
64
}
59
65
60
66
query := strings .Join (cmds , " " )
61
67
cmds = cmds [:0 ]
62
- rl .SetPrompt (initPrompt )
68
+ rl .SetPrompt (prompt )
63
69
rl .SaveHistory (query )
64
70
65
71
rl .Terminal .Print (fmt .Sprintf ("\n --> Executing query: %s\n \n " , query ))
66
72
67
73
schema , rowIter , err := c .executeQuery (query )
68
74
if err != nil {
69
- rl . Terminal . Print ( fmt . Sprintf ( "ERROR: %v\n \n " , err ) )
75
+ red ( "ERROR: %v\n \n " , err )
70
76
continue
71
77
}
72
78
73
79
if err := c .printQuery (schema , rowIter , "pretty" ); err != nil {
74
- rl . Terminal . Print ( fmt . Sprintf ( "ERROR: %v\n \n " , err ) )
80
+ red ( "ERROR: %v\n \n " , err )
75
81
continue
76
82
}
77
83
}
0 commit comments