@@ -2,11 +2,12 @@ package main
2
2
3
3
import (
4
4
"fmt"
5
- "github.com/gookit/color"
6
5
"io"
7
6
"os"
8
7
"strings"
8
+ "time"
9
9
10
+ "github.com/gookit/color"
10
11
"github.com/spf13/cobra"
11
12
)
12
13
@@ -16,25 +17,65 @@ var (
16
17
Short : "render the prompt based on the results of query" ,
17
18
}
18
19
19
- flgRIncomplete = cmdRender .PersistentFlags ().Bool (
20
- "prompt-incomplete" , false ,
21
- "is prompt query done rendering" ,
20
+ flgRLoading = cmdRender .PersistentFlags ().Bool (
21
+ "prompt-loading" , false ,
22
+ "is prompt query not yet done rendering" ,
23
+ )
24
+ flgRColorMode = cmdRender .PersistentFlags ().String (
25
+ "color-mode" , "none" ,
26
+ "color rendering mode of the prompt (zsh, ascii, none)" ,
22
27
)
23
28
flgRMode = cmdRender .PersistentFlags ().String (
24
29
"prompt-mode" , "normal" ,
25
30
"mode of the prompt (normal, edit)" ,
26
31
)
32
+
33
+ // DEPRECATED
27
34
flgRNewline = cmdRender .PersistentFlags ().String (
28
35
"newline" , "\n " ,
29
36
"newline for the prompt" ,
30
37
)
31
38
)
32
39
40
+ var (
41
+ redC = fmt .Sprint
42
+ greenC = fmt .Sprint
43
+ yellowC = fmt .Sprint
44
+ blueC = fmt .Sprint
45
+ magentaC = fmt .Sprint
46
+ normalC = fmt .Sprint
47
+ )
48
+
49
+ func setColorMode (mode string ) {
50
+ wrapC := func (pref , suff string ) func (args ... interface {}) string {
51
+ return func (args ... interface {}) string {
52
+ return pref + fmt .Sprint (args ... ) + suff
53
+ }
54
+ }
55
+
56
+ if mode == "zsh" {
57
+ redC = wrapC ("%F{red}" , "%F{reset}" )
58
+ greenC = wrapC ("%F{green}" , "%F{reset}" )
59
+ yellowC = wrapC ("%F{yellow}" , "%F{reset}" )
60
+ blueC = wrapC ("%F{blue}" , "%F{reset}" )
61
+ magentaC = wrapC ("%F{magenta}" , "%F{reset}" )
62
+ } else if mode == "ascii" {
63
+ redC = color .Red .Render
64
+ greenC = color .Green .Render
65
+ yellowC = color .Yellow .Render
66
+ blueC = color .Blue .Render
67
+ magentaC = color .Magenta .Render
68
+ }
69
+ }
70
+
71
+
33
72
func init () {
34
73
cmdRender .RunE = cmdRenderRun
35
74
}
36
75
37
76
func cmdRenderRun (_ * cobra.Command , _ []string ) error {
77
+ setColorMode (* flgRColorMode )
78
+
38
79
if _ , err := os .Stdin .Stat (); err != nil {
39
80
fmt .Printf ("%#v" , err )
40
81
}
@@ -57,19 +98,21 @@ func cmdRenderRun(_ *cobra.Command, _ []string) error {
57
98
if p ["vcs" ] == "git" {
58
99
var gitParts []string
59
100
60
- gitMark := fmt . Sprint ( "git" )
61
- gitMarkC := color . Green . Render
101
+ gitMark := "git"
102
+ gitMarkC := yellowC
62
103
63
104
gitBranch := fmt .Sprint (p ["vcs_br" ])
64
- gitBranchC := color . Green . Render
105
+ gitBranchC := greenC
65
106
66
107
gitDirtyMarks := ""
108
+ gitDirtyMarksC := redC
67
109
if p ["vcs_dirty" ] != "" && p ["vcs_dirty" ] != "0" {
68
- gitDirtyMarks = fmt .Sprint ("&" )
69
- gitMarkC = color .Yellow .Render
110
+ gitDirtyMarks = "&"
70
111
}
71
112
72
113
distanceMarks := ""
114
+ distanceMarksC := magentaC
115
+
73
116
distanceAhead := strInt (p ["vcs_log_ahead" ])
74
117
distanceBehind := strInt (p ["vcs_log_ahead" ])
75
118
if distanceAhead > 0 || distanceBehind > 0 {
@@ -79,32 +122,80 @@ func cmdRenderRun(_ *cobra.Command, _ []string) error {
79
122
gitParts = append (gitParts , gitMarkC (gitMark ))
80
123
gitParts = append (gitParts , gitBranchC (gitBranch ))
81
124
if len (gitDirtyMarks ) > 0 {
82
- gitParts = append (gitParts , gitDirtyMarks )
125
+ gitParts = append (gitParts , gitDirtyMarksC ( gitDirtyMarks ) )
83
126
}
84
127
if len (distanceMarks ) > 0 {
85
- gitParts = append (gitParts , distanceMarks )
128
+ gitParts = append (gitParts , distanceMarksC ( distanceMarks ) )
86
129
}
87
130
88
131
partsTop = append (partsTop , fmt .Sprintf ("{%v}" , strings .Join (gitParts , ":" )))
89
132
}
90
133
134
+ if p ["stg" ] != "" {
135
+ var stgParts []string
136
+
137
+ stgMark := "stg"
138
+ stgMarkC := yellowC
139
+
140
+ stgTopPatch := p ["stg_top" ]
141
+ stgTopPatchC := greenC
142
+
143
+ stgQueueMark := ""
144
+ stgQueueMarkC := normalC
145
+
146
+ stgQueueLen := strInt (p ["stg_qlen" ])
147
+ stgQueuePos := strInt (p ["stg_qpos" ])
148
+ if stgQueuePos > 0 {
149
+ stgQueueMark = fmt .Sprintf ("%d/%d" , stgQueuePos , stgQueueLen )
150
+ }
151
+
152
+ if strInt (p ["stg_dirty" ]) != 0 {
153
+ stgTopPatchC = redC
154
+ }
155
+
156
+ stgParts = append (stgParts , stgMarkC (stgMark ))
157
+
158
+ if len (stgTopPatch ) > 0 {
159
+ stgParts = append (stgParts , stgTopPatchC (stgTopPatch ))
160
+
161
+ }
162
+
163
+ if len (stgQueueMark ) > 0 {
164
+ stgParts = append (stgParts , stgQueueMarkC (stgQueueMark ))
165
+ }
166
+
167
+ partsTop = append (partsTop , fmt .Sprintf ("{%v}" , strings .Join (stgParts , ":" )))
168
+ }
169
+
91
170
var partsBottom []string
92
171
if strInt (p ["st" ]) > 0 {
93
- partsBottom = append (partsBottom , fmt .Sprintf ("[%v]" , p ["st" ]))
172
+ partsBottom = append (partsBottom , redC ("[" + p ["st" ]+ "]" ))
173
+ }
174
+
175
+ if p ["pid_parent_exec" ] != "" {
176
+ partsBottom = append (partsBottom , "(" + p ["pid_parent_exec" ]+ ")" )
94
177
}
95
- partsBottom = append (partsBottom , fmt .Sprintf ("(%v)" , p ["wd" ]))
178
+
179
+ partsBottom = append (partsBottom , yellowC ("(" )+ blueC (p ["wd_trim" ])+ yellowC (")" ))
180
+
96
181
if p ["ds" ] != "" {
97
182
partsBottom = append (partsBottom , fmt .Sprintf ("%v" , p ["ds" ]))
98
183
}
99
- partsBottom = append (partsBottom , fmt .Sprintf ("[%v]" , p ["ts" ]))
100
184
101
- promptMarker := fmt .Sprint (">" )
185
+ nowTS := time .Now ()
186
+ cmdTS := timeFMT (nowTS )
187
+ if len (p ["ts" ]) != 0 {
188
+ cmdTS = p ["ts" ]
189
+ }
190
+ partsBottom = append (partsBottom , fmt .Sprintf ("[%v]" , cmdTS ))
191
+
192
+ promptMarker := magentaC (">" )
102
193
if * flgRMode == "edit" {
103
- promptMarker = fmt . Sprint ("<" )
194
+ promptMarker = redC ("<" )
104
195
}
105
196
106
197
promptStatusMarker := ":: "
107
- if * flgRIncomplete {
198
+ if * flgRLoading {
108
199
promptStatusMarker = ":? "
109
200
}
110
201
0 commit comments