~mh/proc

d63d2779cc21473c56d647faea04b4c76d0ced2d — Max Hille 3 months ago d4ed0b2
Add job name color
1 files changed, 19 insertions(+), 2 deletions(-)

M main.go
M main.go => main.go +19 -2
@@ 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)
}