Skip to content

Commit

Permalink
Improve printRoutesMessage (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Dec 30, 2021
1 parent 894fa9d commit e26ed83
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app.go
Expand Up @@ -1260,7 +1260,13 @@ func (app *App) printRoutesMessage() {
routes = append(routes, newRoute)
}
}
w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)

out := colorable.NewColorableStdout()
if os.Getenv("TERM") == "dumb" || os.Getenv("NO_COLOR") == "1" || (!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) {
out = colorable.NewNonColorable(os.Stdout)
}

w := tabwriter.NewWriter(out, 1, 1, 1, ' ', 0)
// Sort routes by path
sort.Slice(routes, func(i, j int) bool {
return routes[i].path < routes[j].path
Expand All @@ -1270,5 +1276,6 @@ func (app *App) printRoutesMessage() {
for _, route := range routes {
_, _ = fmt.Fprintf(w, "%s%s\t%s| %s%s\t%s| %s%s\t%s| %s%s\n", cBlue, route.method, cWhite, cGreen, route.path, cWhite, cCyan, route.name, cWhite, cYellow, route.handlers)
}

_ = w.Flush()
}

0 comments on commit e26ed83

Please sign in to comment.