Skip to content

Commit

Permalink
use ladicle/tabwrite to handle color
Browse files Browse the repository at this point in the history
  • Loading branch information
vmaerten committed May 13, 2024
1 parent 534bac7 commit 1acd5d9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
)

require (
github.com/Ladicle/tabwriter v1.0.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Ladicle/tabwriter v1.0.0 h1:DZQqPvMumBDwVNElso13afjYLNp0Z7pHqHnu0r4t9Dg=
github.com/Ladicle/tabwriter v1.0.0/go.mod h1:c4MdCjxQyTbGuQO/gvqJ+IA/89UEwrsD6hUCW98dyp4=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
Expand Down
16 changes: 3 additions & 13 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"io"
"os"
"strings"
"text/tabwriter"

"github.com/Ladicle/tabwriter"
"golang.org/x/sync/errgroup"

"github.com/go-task/task/v3/internal/editors"
Expand Down Expand Up @@ -105,18 +105,8 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) {
for _, task := range tasks {
e.Logger.FOutf(w, logger.Yellow, "* ")
e.Logger.FOutf(w, logger.Green, task.Task)
desc := strings.Split(strings.TrimSuffix(task.Desc, "\n"), "\n")

e.Logger.FOutf(w, logger.Default, ": \t%s", desc[0])

for _, d := range desc[1:] {
_, _ = fmt.Fprint(w, "\n")
// We need to keep the same color as if it was a new task to keep the output consistent
// because tabwriter cannot handle color codes
e.Logger.FOutf(w, logger.Yellow, "")
e.Logger.FOutf(w, logger.Green, "")
e.Logger.FOutf(w, logger.Default, "\t%s", d)
}
desc := strings.ReplaceAll(strings.TrimSuffix(task.Desc, "\n"), "\n", "\n\t")
e.Logger.FOutf(w, logger.Default, ": \t%s", desc)
if len(task.Aliases) > 0 {
e.Logger.FOutf(w, logger.Cyan, "\t(aliases: %s)", strings.Join(task.Aliases, ", "))
}
Expand Down
5 changes: 2 additions & 3 deletions internal/experiments/experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"path/filepath"
"slices"
"strings"
"text/tabwriter"

"github.com/Ladicle/tabwriter"
"github.com/joho/godotenv"
"github.com/spf13/pflag"

Expand Down Expand Up @@ -96,8 +96,7 @@ func readDotEnv() {
func printExperiment(w io.Writer, l *logger.Logger, x Experiment) {
l.FOutf(w, logger.Yellow, "* ")
l.FOutf(w, logger.Green, x.Name)
l.FOutf(w, logger.Default, ": \t%s", x.String())
fmt.Fprintf(w, "\n")
l.FOutf(w, logger.Default, ": \t%s\n", x.String())
}

func List(l *logger.Logger) error {
Expand Down

0 comments on commit 1acd5d9

Please sign in to comment.