8000 feat(cdsctl): sort hatchery workers count by status for termui (#4199) · ovh/cds@2374931 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 2374931

Browse files
richardltyesnault
authored andcommitted
feat(cdsctl): sort hatchery workers count by status for termui (#4199)
1 parent 33ce44b commit 2374931

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

cli/cdsctl/monitoring.go

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,12 @@ const (
284284
)
285285

286286
func (ui *Termui) staticRender() {
287+
checking, checkingColor := statusShort(sdk.StatusChecking.String())
287288
waiting, waitingColor := statusShort(sdk.StatusWaiting.String())
288289
building, buildingColor := statusShort(sdk.StatusBuilding.String())
289290
disabled, disabledColor := statusShort(sdk.StatusDisabled.String())
290-
ui.header.Text = fmt.Sprintf("[CDS | (h)elp | (q)uit | Legend: ](fg-cyan) [Waiting:%s](%s) [Building:%s](%s) [Disabled:%s](%s)",
291+
ui.header.Text = fmt.Sprintf("[CDS | (h)elp | (q)uit | Legend:](fg-cyan) [Checking:%s](%s) [Waiting:%s](%s) [Building:%s](%s) [Disabled:%s](%s)",
292+
checking, checkingColor,
291293
waiting, waitingColor,
292294
building, buildingColor,
293295
disabled, disabledColor)
@@ -493,30 +495,41 @@ func (ui *Termui) computeStatusHatcheriesWorkers(workers []sdk.Worker) {
493495
status[w.Status.String()] = status[w.Status.String()] + 1
494496
}
495497

498+
sort.Slice(statusTitle, func(i, j int) bool {
499+
return statusWeight(statusTitle[i]) < statusWeight(statusTitle[j])
500+
})
501+
496502
var items []string
497503
sort.Strings(hatcheryNames)
498504
for _, name := range hatcheryNames {
499505
v := hatcheries[name]
500506
var t string
507+
var statusText []string
501508
for _, status := range statusTitle {
502509
if v[status] > 0 {
503510
icon, color := statusShort(status)
504-
t = fmt.Sprintf("%s[ %d%s ](%s)", t, v[status], icon, color)
511+
statusText = append(statusText, fmt.Sprintf("[%d%s](%s)", v[status], icon, color))
505512
}
506513
}
507-
if len(t) == 0 {
508-
t = fmt.Sprintf("%s[ _ ](fg-white)", t)
514+
if len(statusText) == 0 {
515+
t = fmt.Sprintf(" [_ %s](fg-white)", name)
516+
} else {
517+
t = fmt.Sprintf(" %s [%s](fg-white)", strings.Join(statusText, " "), name)
509518
}
510-
t = fmt.Sprintf("%s[ %s](fg-white)", t, name)
511519
items = append(items, t)
512520
}
513521
ui.statusHatcheriesWorkers.SetItems(items...)
514522

515-
sort.Strings(statusTitle)
516-
title := " Hatcheries "
523+
var titleStatusText []string
517524
for _, s := range statusTitle {
518-
icon, color := statusShort(s)
519-
title = fmt.Sprintf("%s[%d%s](%s) ", title, status[s], icon, color)
525+
if status[s] > 0 {
526+
icon, color := statusShort(s)
527+
titleStatusText = append(titleStatusText, fmt.Sprintf("[%d%s](%s)", status[s], icon, color))
528+
}
529+
}
530+
title := " Hatcheries "
531+
if len(titleStatusText) > 0 {
532+
title = fmt.Sprintf("%s%s ", title, strings.Join(titleStatusText, " "))
520533
}
521534
ui.statusHatcheriesWorkers.BorderLabel = title
522535
}
@@ -632,13 +645,27 @@ func statusShort(status string) (string, string) {
632645
case sdk.StatusBuilding.String():
633646
return "b", "fg-blue"
634647
case sdk.StatusDisabled.String():
635-
return "d", "fg-grey"
648+
return "d", "fg-white"
636649
case sdk.StatusChecking.String():
637650
return "c", "fg-yellow"
638651
}
639652
return status, "fg-default"
640653
}
641654

655+
func statusWeight(status string) int {
656+
switch status {
657+
case sdk.StatusDisabled.String():
658+
return 4
659+
case sdk.StatusBuilding.String():
660+
return 3
661+
case sdk.StatusWaiting.String():
662+
return 2
663+
case sdk.StatusChecking.String():
664+
return 1
665+
}
666+
return 0
667+
}
668+
642669
func pad(t string, size int) string {
643670
if len(t) > size {
644671
return t[0:size-3] + "..."

0 commit comments

Comments
 (0)
0