mirror of
https://github.com/go-task/task.git
synced 2025-01-20 04:59:37 +02:00
Merge pull request #874 from go-task/845-colorize-output
Colorize --list, --list-all and --summary output
This commit is contained in:
commit
d2061ec898
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Add colored output to `--list`, `--list-all` and `--summary` flags ([#845](https://github.com/go-task/task/pull/845), [#874](https://github.com/go-task/task/pull/874)).
|
||||||
- Fix unexpected behavior where `label:` was being shown instead of the task
|
- Fix unexpected behavior where `label:` was being shown instead of the task
|
||||||
name on `--list`
|
name on `--list`
|
||||||
([#603](https://github.com/go-task/task/issues/603), [#877](https://github.com/go-task/task/pull/877)).
|
([#603](https://github.com/go-task/task/issues/603), [#877](https://github.com/go-task/task/pull/877)).
|
||||||
|
7
help.go
7
help.go
@ -42,9 +42,12 @@ func (e *Executor) printTasks(listAll bool) {
|
|||||||
e.Logger.Outf(logger.Default, "task: Available tasks for this project:")
|
e.Logger.Outf(logger.Default, "task: Available tasks for this project:")
|
||||||
|
|
||||||
// Format in tab-separated columns with a tab stop of 8.
|
// Format in tab-separated columns with a tab stop of 8.
|
||||||
w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0)
|
w := tabwriter.NewWriter(e.Stdout, 0, 8, 6, ' ', 0)
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
fmt.Fprintf(w, "* %s: \t%s\n", task.Task, task.Desc)
|
e.Logger.FOutf(w, logger.Yellow, "* ")
|
||||||
|
e.Logger.FOutf(w, logger.Green, task.Task)
|
||||||
|
e.Logger.FOutf(w, logger.Default, ": \t%s", task.Desc)
|
||||||
|
fmt.Fprint(w, "\n")
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,11 @@ type Logger struct {
|
|||||||
|
|
||||||
// Outf prints stuff to STDOUT.
|
// Outf prints stuff to STDOUT.
|
||||||
func (l *Logger) Outf(color Color, s string, args ...interface{}) {
|
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 {
|
if len(args) == 0 {
|
||||||
s, args = "%s", []interface{}{s}
|
s, args = "%s", []interface{}{s}
|
||||||
}
|
}
|
||||||
@ -60,7 +65,7 @@ func (l *Logger) Outf(color Color, s string, args ...interface{}) {
|
|||||||
color = Default
|
color = Default
|
||||||
}
|
}
|
||||||
print := color()
|
print := color()
|
||||||
print(l.Stdout, s+"\n", args...)
|
print(w, s, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerboseOutf prints stuff to STDOUT if verbose mode is enabled.
|
// VerboseOutf prints stuff to STDOUT if verbose mode is enabled.
|
||||||
|
@ -56,7 +56,8 @@ func printTaskSummary(l *logger.Logger, t *taskfile.Task) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printTaskName(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, "")
|
l.Outf(logger.Default, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,10 +95,11 @@ func printTaskCommands(l *logger.Logger, t *taskfile.Task) {
|
|||||||
l.Outf(logger.Default, "commands:")
|
l.Outf(logger.Default, "commands:")
|
||||||
for _, c := range t.Cmds {
|
for _, c := range t.Cmds {
|
||||||
isCommand := c.Cmd != ""
|
isCommand := c.Cmd != ""
|
||||||
|
l.FOutf(l.Stdout, logger.Default, " - ")
|
||||||
if isCommand {
|
if isCommand {
|
||||||
l.Outf(logger.Default, " - %s", c.Cmd)
|
l.FOutf(l.Stdout, logger.Yellow, "%s\n", c.Cmd)
|
||||||
} else {
|
} else {
|
||||||
l.Outf(logger.Default, " - Task: %s", c.Task)
|
l.FOutf(l.Stdout, logger.Green, "Task: %s\n", c.Task)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user