ls output bikeshedding

This commit is contained in:
Joel Elkins 2024-03-04 23:48:51 -06:00
parent 569f0fac8d
commit ce0710b0d1
Signed by: joel
GPG Key ID: 133589DC38921AE2
1 changed files with 20 additions and 7 deletions

View File

@ -103,6 +103,7 @@ ccl ls squid`,
}
return
} else {
fmt.Fprint(w, "Error\n")
return
}
}
@ -164,25 +165,36 @@ ccl ls squid`,
return
}
// By default, we are outputing to a terminal or pipe. Other cases
// should have been handled above and returned.
tw := ansiterm.NewTabWriter(w, 0, 0, 2, ' ', 0)
defer tw.Flush()
defcolor := ansiterm.Foreground(ansiterm.Default)
red := ansiterm.Foreground(ansiterm.Red)
yellow := ansiterm.Foreground(ansiterm.Yellow)
bold := ansiterm.Styles(ansiterm.Bold)
ital := ansiterm.Styles(ansiterm.Italic)
defer tw.Flush()
title := ansiterm.Styles(ansiterm.Bold, ansiterm.Underline)
name := ansiterm.Styles(ansiterm.Italic)
const IMGLEN int = 20
if conn != nil {
bold.Fprint(tw, "CATEGORY\tGROUP\tNAME\tIMAGE\tCREATED\t RUNNING\t CPU%\t MEM%\t\n")
title.Fprint(tw, "CATEGORY\tGROUP\tNAME\tIMAGE\tCREATED\t RUNNING\t CPU%\t MEM%\t\n")
for _, c := range conts {
defcolor.Fprintf(tw, "%s\t%5d\t", c.Category, c.StartGroup)
ital.Fprintf(tw, "%s\t", c.Name)
defcolor.Fprintf(tw, "%s\t", c.Image)
name.Fprintf(tw, "%s\t", c.Name)
dispimg := c.Image
if len(dispimg) > IMGLEN {
dispimg = dispimg[:IMGLEN] + "…"
}
defcolor.Fprintf(tw, "%s\t", dispimg)
if c.IsCreated() {
defcolor.Fprint(tw, " ✓\t")
} else {
red.Fprint(tw, " ✗\t")
}
if c.IsRunning() {
raw := int64(c.RunningTime().Seconds())
seconds := raw % 60
@ -192,6 +204,7 @@ ccl ls squid`,
} else {
red.Fprint(tw, " ✗\t")
}
if stats := c.GetStats(); c.IsRunning() && stats != nil {
for _, st := range []float64{stats.CPU, stats.MemPerc} {
hi := defcolor
@ -210,7 +223,7 @@ ccl ls squid`,
}
} else {
titlemsg := "CATEGORY\tGROUP\tNAME\tIMAGE\n"
bold.Fprint(tw, titlemsg)
title.Fprint(tw, titlemsg)
for _, c := range conts {
data := []interface{}{c.Category, c.StartGroup, c.Name, c.Image}