github.com/benchkram/bob@v0.0.0-20240314204020-b7a57f2f9be9/bob/playbook/colors.go (about)

     1  package playbook
     2  
     3  import (
     4  	"fmt"
     5  	"sort"
     6  
     7  	"github.com/benchkram/bob/pkg/boblog"
     8  	"github.com/logrusorgru/aurora"
     9  )
    10  
    11  //	     Run this to pick a new color
    12  //		 	for i := uint8(16); i <= 231; i++ {
    13  //				fmt.Println(i, aurora.Index(i, "pew-pew"))
    14  //			}
    15  var colorPool = []aurora.Color{
    16  	aurora.GreenFg,
    17  	aurora.BlueFg,
    18  	aurora.CyanFg,
    19  	aurora.MagentaFg,
    20  	aurora.YellowFg,
    21  	aurora.RedFg,
    22  	aurora.Index(42, nil).Color(),
    23  	aurora.Index(45, nil).Color(),
    24  	aurora.Index(51, nil).Color(),
    25  	aurora.Index(111, nil).Color(),
    26  	aurora.Index(141, nil).Color(),
    27  	aurora.Index(225, nil).Color(),
    28  }
    29  
    30  // pickTaskColors picks a display color for each task in the playbook.
    31  func (p *Playbook) pickTaskColors() {
    32  	tasks := []string{}
    33  	for _, t := range p.Tasks {
    34  		tasks = append(tasks, t.Name())
    35  	}
    36  	sort.Strings(tasks)
    37  
    38  	// Adjust padding of first column based on the taskname length.
    39  	// Also assign fixed color to the tasks.
    40  	p.namePad = 0
    41  	for i, name := range tasks {
    42  		if len(name) > p.namePad {
    43  			p.namePad = len(name)
    44  		}
    45  
    46  		color := colorPool[i%len(colorPool)]
    47  		p.Tasks[name].Task.SetColor(color)
    48  	}
    49  	p.namePad += 14
    50  
    51  	dependencies := len(tasks) - 1
    52  	rootName := p.Tasks[p.root].ColoredName()
    53  	boblog.Log.V(1).Info(fmt.Sprintf("Running task %s with %d dependencies", rootName, dependencies))
    54  }