feat: colorize tasks in prefixed output
~Introduces a new option to the prefixed outputter to colorize the task names according to a sequence of colors. Helps distinguish what logging message comes from which task.~ As requested, this is now default behavior.
The color is deterministic in the sense that it indexes the tasks with a color according to the order they appear in logs. Once the color is determined, it sticks with that color for the rest of the task. If more tasks run than there are colors, the colors will loop.
This method was chosen over a seeded random, due to the risk that a seeded randomizer often results in duplicate colors, even with only a small number of tasks running. Instead, this ensures that no duplicate colors are chosen given the number of tasks does not exceed the number of colors. For example, using the prefix as the seed (through MD5 to get uint representation for rand.NewSource) gives the tasks "watch-templ" and "watch-tailwind" the same color. This is not preferable.
The sequence of colors was created to put semantic colors closer to the end of the sequence (red & green are success & failure colors), and the sequence consists of 2 parts, the non-bolded versions and the bolded versions. Non-bolded colors are chosen first, and bolded colors later, to provide more possible distinguishable colors with a large number of tasks. The test checks for proper looping of the color sequence by logging 16 tasks, whereas the sequence has 12 colors.
Screenshot
Checklist
- [x] Backwards compatible
- [x] Tests written & passing
- [ ] CLI flags updated (
--output-prefix-color) - [ ] Schema updated
- [ ] Docs usage & API reference updated
Future improvements
- Ability to configure exact color per task definition
- Configure the sequence of colors
- Determine the colors on setup according to the task list, instead of lazily as the logs come in. This ensures for a given set of tasks, the colors will always be the same.