4
4
"fmt"
5
5
"io"
6
6
"sort"
7
+
7
8
"strings"
8
9
9
10
"github.com/cppforlife/go-cli-ui/ui"
@@ -17,14 +18,15 @@ type TreeView struct {
17
18
Source string
18
19
ResourceMap [][]krsc.Resource
19
20
Sort bool
21
+ Verbose bool
20
22
}
21
23
22
24
func (v TreeView ) Print (ui ui.UI ) {
23
25
groupHeader := uitable .NewHeader ("Group" )
24
26
groupHeader .Hidden = true
25
27
26
28
versionHeader := uitable .NewHeader ("Version" )
27
- versionHeader .Hidden = true
29
+ versionHeader .Hidden = ! v . Verbose
28
30
29
31
table := uitable.Table {
30
32
Title : fmt .Sprintf ("Resources in %s" , v .Source ),
@@ -34,8 +36,8 @@ func (v TreeView) Print(ui ui.UI) {
34
36
groupHeader ,
35
37
uitable .NewHeader ("Namespace" ),
36
38
uitable .NewHeader ("Name" ),
37
- uitable .NewHeader ("Kind" ),
38
39
versionHeader ,
40
+ uitable .NewHeader ("Kind" ),
39
41
uitable .NewHeader ("Ready" ),
40
42
uitable .NewHeader ("Reason" ),
41
43
},
@@ -148,6 +150,7 @@ func (v TreeView) addBlankRow(table *uitable.Table) {
148
150
uitable .NewValueString (" " ),
149
151
uitable .NewValueString (" " ),
150
152
uitable .NewValueString (" " ),
153
+ uitable .NewValueString (" " ),
151
154
}
152
155
table .Rows = append (table .Rows , row )
153
156
}
@@ -172,24 +175,26 @@ func (v TreeView) addRows(table *uitable.Table, rt resourceTree, depth int, conn
172
175
173
176
var delim string
174
177
if depth > 0 {
175
- delim = fmt .Sprintf ("%sL " , connector )
178
+ delim = fmt .Sprintf ("%sL" , connector )
179
+ if ! hasSibling {
180
+ delim += "_"
181
+ }
182
+ delim += " "
176
183
}
177
184
178
- delim = strings .ReplaceAll (delim , "|L" , "L" )
179
-
180
185
row := []uitable.Value {
181
186
uitable .NewValueString ("" ),
182
187
uitable .NewValueString (resource .Namespace ()),
183
188
uitable .NewValueString (resource .Name ()),
184
- ValueColored {
189
+ uitable .NewValueString (resource .APIVersion ()),
190
+ ValueEncoded {
185
191
S : delim + resource .Kind (),
186
192
Func : func (str string , opts ... interface {}) string {
187
193
result := fmt .Sprintf (str , opts ... )
188
- return strings .Replace ( result , delim , color . New ( color . Faint ). Sprintf ( "%s " , delim ), - 1 )
194
+ return strings .ReplaceAll ( strings . ReplaceAll ( strings . ReplaceAll ( result , "|L" , "├─" ), "| " , "│" ), "L_" , "└─" )
189
195
},
190
196
},
191
- uitable .NewValueString (resource .APIVersion ()),
192
- ValueColored {
197
+ ValueEncoded {
193
198
S : msg ,
194
199
Func : func (str string , opts ... interface {}) string {
195
200
result := fmt .Sprintf (str , opts ... )
@@ -202,7 +207,7 @@ func (v TreeView) addRows(table *uitable.Table, rt resourceTree, depth int, conn
202
207
return result
203
208
},
204
209
},
205
- ValueColored {
210
+ ValueEncoded {
206
211
S : reason ,
207
212
Func : func (str string , opts ... interface {}) string {
208
213
result := fmt .Sprintf (str , opts ... )
@@ -227,15 +232,15 @@ func (v TreeView) addRows(table *uitable.Table, rt resourceTree, depth int, conn
227
232
}
228
233
}
229
234
230
- type ValueColored struct {
235
+ type ValueEncoded struct {
231
236
S string
232
237
Func func (string , ... interface {}) string
233
238
}
234
239
235
- func (t ValueColored ) String () string { return t .S }
236
- func (t ValueColored ) Value () uitable.Value { return t }
237
- func (t ValueColored ) Compare (other uitable.Value ) int { panic ("Never called" ) }
240
+ func (t ValueEncoded ) String () string { return t .S }
241
+ func (t ValueEncoded ) Value () uitable.Value { return t }
242
+ func (t ValueEncoded ) Compare (other uitable.Value ) int { panic ("Never called" ) }
238
243
239
- func (t ValueColored ) Fprintf (w io.Writer , pattern string , rest ... interface {}) (int , error ) {
244
+ func (t ValueEncoded ) Fprintf (w io.Writer , pattern string , rest ... interface {}) (int , error ) {
240
245
return fmt .Fprintf (w , "%s" , t .Func (pattern , rest ... ))
241
246
}
0 commit comments