From d63d2779cc21473c56d647faea04b4c76d0ced2d Mon Sep 17 00:00:00 2001 From: Max Hille Date: Thu, 6 Jun 2024 11:04:04 +0200 Subject: [PATCH] Add job name color --- main.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 135f233..b54c3ec 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ type job struct { name string cmd []string stopped bool + color int } type output struct { @@ -27,6 +28,16 @@ type output struct { var pad = 0 +const ( + Red = 1 + Green = 2 + Yellow = 3 + Blue = 4 + Magenta = 5 + Cyan = 6 + White = 7 +) + func main() { jobs, err := load() if err != nil { @@ -47,8 +58,14 @@ func main() { stdouts := make(chan output) stderrs := make(chan output) + // colors used for job names + colors := []int{Blue, Magenta, Cyan, Yellow} + for i := range jobs { job := &jobs[i] + + job.color = colors[i%len(colors)] + cmd := exec.Command(job.cmd[0], job.cmd[1:]...) stdout, err := cmd.StdoutPipe() @@ -107,12 +124,12 @@ func main() { } func (job *job) printError(err error) { - formatErr := fmt.Sprintf("%%%ds | \x1b[31m%%v\x1b[0m\n", pad) + formatErr := fmt.Sprintf("%%%ds | \x1b[3%dm%%v\x1b[0m\n", pad, Red) fmt.Printf(formatErr, job.name, err) } func (job *job) print(str string) { - format := fmt.Sprintf("%%%ds | %%v\n", pad) + format := fmt.Sprintf("\x1b[3%dm%%%ds\x1b[0m | %%v\n", job.color, pad) fmt.Printf(format, job.name, str) } -- 2.45.2