feat: add coloured output to --list, --list-all and --summary flags

feat: add coloured output to --list and --list-all

feat: add coloured output to --summary

chore: update colors

refactor: better consistency in writer calls in printTasks

feat: subtasks are printed green in --summary
This commit is contained in:
Pete Davison
2022-09-29 17:13:12 +00:00
parent fb0e43989d
commit 8ce1782380
3 changed files with 16 additions and 6 deletions

View File

@@ -53,6 +53,11 @@ type Logger struct {
// Outf prints stuff to STDOUT.
func (l *Logger) Outf(color Color, s string, args ...interface{}) {
l.FOutf(l.Stdout, color, s+"\n", args...)
}
// FOutf prints stuff to the given writer.
func (l *Logger) FOutf(w io.Writer, color Color, s string, args ...interface{}) {
if len(args) == 0 {
s, args = "%s", []interface{}{s}
}
@@ -60,7 +65,7 @@ func (l *Logger) Outf(color Color, s string, args ...interface{}) {
color = Default
}
print := color()
print(l.Stdout, s+"\n", args...)
print(w, s, args...)
}
// VerboseOutf prints stuff to STDOUT if verbose mode is enabled.

View File

@@ -56,7 +56,8 @@ func printTaskSummary(l *logger.Logger, t *taskfile.Task) {
}
func printTaskName(l *logger.Logger, t *taskfile.Task) {
l.Outf(logger.Default, "task: %s", t.Name())
l.FOutf(l.Stdout, logger.Default, "task: ")
l.FOutf(l.Stdout, logger.Green, "%s\n", t.Name())
l.Outf(logger.Default, "")
}
@@ -94,10 +95,11 @@ func printTaskCommands(l *logger.Logger, t *taskfile.Task) {
l.Outf(logger.Default, "commands:")
for _, c := range t.Cmds {
isCommand := c.Cmd != ""
l.FOutf(l.Stdout, logger.Default, " - ")
if isCommand {
l.Outf(logger.Default, " - %s", c.Cmd)
l.FOutf(l.Stdout, logger.Yellow, "%s\n", c.Cmd)
} else {
l.Outf(logger.Default, " - Task: %s", c.Task)
l.FOutf(l.Stdout, logger.Green, "Task: %s\n", c.Task)
}
}
}