Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable color by default only if os.Stdout is a TTY #6696

Merged
merged 3 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/types"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/lib/tablewriter"
)

Expand Down Expand Up @@ -1231,9 +1232,10 @@ var clientListRetrievalsCmd = &cli.Command{
Usage: "print verbose deal details",
},
&cli.BoolFlag{
Name: "color",
Usage: "use color in display output",
Value: true,
Name: "color",
Usage: "use color in display output",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
&cli.BoolFlag{
Name: "show-failed",
Expand Down Expand Up @@ -1804,9 +1806,10 @@ var clientListDeals = &cli.Command{
Usage: "print verbose deal details",
},
&cli.BoolFlag{
Name: "color",
Usage: "use color in display output",
Value: true,
Name: "color",
Usage: "use color in display output",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
&cli.BoolFlag{
Name: "show-failed",
Expand Down Expand Up @@ -2334,9 +2337,10 @@ var clientListTransfers = &cli.Command{
Usage: "print verbose transfer details",
},
&cli.BoolFlag{
Name: "color",
Usage: "use color in display output",
Value: true,
Name: "color",
Usage: "use color in display output",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
&cli.BoolFlag{
Name: "completed",
Expand Down
14 changes: 14 additions & 0 deletions cli/util/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cliutil

import (
"os"

"github.com/mattn/go-isatty"
)

// DefaultColorUse is the globally referenced variable for all Lotus CLI tools
// It sets to `true` if STDOUT is a TTY or if the variable GOLOG_LOG_FMT is set
// to color (as recognizd by github.com/ipfs/go-log/v2)
var DefaultColorUse = os.Getenv("GOLOG_LOG_FMT") == "color" ||
isatty.IsTerminal(os.Stdout.Fd()) ||
isatty.IsCygwinTerminal(os.Stdout.Fd())
6 changes: 4 additions & 2 deletions cmd/lotus-shed/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/lib/tablewriter"
)

Expand Down Expand Up @@ -265,8 +266,9 @@ var actorControlList = &cli.Command{
Name: "verbose",
},
&cli.BoolFlag{
Name: "color",
Value: true,
Name: "color",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
},
Action: func(cctx *cli.Context) error {
Expand Down
6 changes: 4 additions & 2 deletions cmd/lotus-storage-miner/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/lib/tablewriter"
)

Expand Down Expand Up @@ -388,8 +389,9 @@ var actorControlList = &cli.Command{
Name: "verbose",
},
&cli.BoolFlag{
Name: "color",
Value: true,
Name: "color",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
},
Action: func(cctx *cli.Context) error {
Expand Down
5 changes: 4 additions & 1 deletion cmd/lotus-storage-miner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/lib/lotuslog"
"github.com/filecoin-project/lotus/lib/tracing"
"github.com/filecoin-project/lotus/node/repo"
Expand Down Expand Up @@ -81,7 +82,9 @@ func main() {
Aliases: []string{"a"},
},
&cli.BoolFlag{
Name: "color",
Name: "color",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
&cli.StringFlag{
Name: "repo",
Expand Down
8 changes: 5 additions & 3 deletions cmd/lotus-storage-miner/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
)

var CidBaseFlag = cli.StringFlag{
Expand Down Expand Up @@ -752,9 +753,10 @@ var transfersListCmd = &cli.Command{
Usage: "print verbose transfer details",
},
&cli.BoolFlag{
Name: "color",
Usage: "use color in display output",
Value: true,
Name: "color",
Usage: "use color in display output",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
&cli.BoolFlag{
Name: "completed",
Expand Down
13 changes: 11 additions & 2 deletions cmd/lotus-storage-miner/sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
)

var sealingCmd = &cli.Command{
Expand All @@ -36,7 +37,11 @@ var sealingWorkersCmd = &cli.Command{
Name: "workers",
Usage: "list workers",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "color"},
&cli.BoolFlag{
Name: "color",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
},
Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color")
Expand Down Expand Up @@ -127,7 +132,11 @@ var sealingJobsCmd = &cli.Command{
Name: "jobs",
Usage: "list running jobs",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "color"},
&cli.BoolFlag{
Name: "color",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
&cli.BoolFlag{
Name: "show-ret-done",
Usage: "show returned but not consumed calls",
Expand Down
8 changes: 5 additions & 3 deletions cmd/lotus-storage-miner/sectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/filecoin-project/lotus/lib/tablewriter"

lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
)

Expand Down Expand Up @@ -161,9 +162,10 @@ var sectorsListCmd = &cli.Command{
Usage: "show removed sectors",
},
&cli.BoolFlag{
Name: "color",
Aliases: []string{"c"},
Value: true,
Name: "color",
Aliases: []string{"c"},
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
&cli.BoolFlag{
Name: "fast",
Expand Down
12 changes: 9 additions & 3 deletions cmd/lotus-storage-miner/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/extern/sector-storage/fsutil"
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
Expand Down Expand Up @@ -166,7 +167,11 @@ var storageListCmd = &cli.Command{
Name: "list",
Usage: "list local storage paths",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "color"},
&cli.BoolFlag{
Name: "color",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
},
Subcommands: []*cli.Command{
storageListSectorsCmd,
Expand Down Expand Up @@ -478,8 +483,9 @@ var storageListSectorsCmd = &cli.Command{
Usage: "get list of all sector files",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "color",
Value: true,
Name: "color",
Value: cliutil.DefaultColorUse,
DefaultText: "depends on output being a TTY",
},
},
Action: func(cctx *cli.Context) error {
Expand Down
16 changes: 8 additions & 8 deletions documentation/en/cli-lotus-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ COMMANDS:

GLOBAL OPTIONS:
--actor value, -a value specify other actor to check state for (read only)
--color (default: false)
--color (default: depends on output being a TTY)
--miner-repo value, --storagerepo value Specify miner repo path. flag(storagerepo) and env(LOTUS_STORAGE_PATH) are DEPRECATION, will REMOVE SOON (default: "~/.lotusminer") [$LOTUS_MINER_PATH, $LOTUS_STORAGE_PATH]
--help, -h show help (default: false)
--version, -v print the version (default: false)
Expand Down Expand Up @@ -295,7 +295,7 @@ USAGE:

OPTIONS:
--verbose (default: false)
--color (default: true)
--color (default: depends on output being a TTY)
--help, -h show help (default: false)

```
Expand Down Expand Up @@ -888,7 +888,7 @@ USAGE:

OPTIONS:
--verbose, -v print verbose transfer details (default: false)
--color use color in display output (default: true)
--color use color in display output (default: depends on output being a TTY)
--completed show completed data transfers (default: false)
--watch watch deal updates in real-time, rather than a one time list (default: false)
--show-failed show failed/cancelled transfers (default: false)
Expand Down Expand Up @@ -1344,7 +1344,7 @@ USAGE:

OPTIONS:
--show-removed show removed sectors (default: false)
--color, -c (default: true)
--color, -c (default: depends on output being a TTY)
--fast don't show on-chain info for better performance (default: false)
--events display number of events the sector has received (default: false)
--seal-time display how long it took for the sector to be sealed (default: false)
Expand Down Expand Up @@ -1739,7 +1739,7 @@ COMMANDS:
help, h Shows a list of commands or help for one command

OPTIONS:
--color (default: false)
--color (default: depends on output being a TTY)
--help, -h show help (default: false)
--version, -v print the version (default: false)

Expand All @@ -1754,7 +1754,7 @@ USAGE:
lotus-miner storage list sectors [command options] [arguments...]

OPTIONS:
--color (default: true)
--color (default: depends on output being a TTY)
--help, -h show help (default: false)

```
Expand Down Expand Up @@ -1816,7 +1816,7 @@ USAGE:
lotus-miner sealing jobs [command options] [arguments...]

OPTIONS:
--color (default: false)
--color (default: depends on output being a TTY)
--show-ret-done show returned but not consumed calls (default: false)
--help, -h show help (default: false)

Expand All @@ -1831,7 +1831,7 @@ USAGE:
lotus-miner sealing workers [command options] [arguments...]

OPTIONS:
--color (default: false)
--color (default: depends on output being a TTY)
--help, -h show help (default: false)

```
Expand Down
6 changes: 3 additions & 3 deletions documentation/en/cli-lotus.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ CATEGORY:

OPTIONS:
--verbose, -v print verbose deal details (default: false)
--color use color in display output (default: true)
--color use color in display output (default: depends on output being a TTY)
--show-failed show failed/failing deals (default: true)
--completed show completed retrievals (default: false)
--watch watch deal updates in real-time, rather than a one time list (default: false)
Expand Down Expand Up @@ -609,7 +609,7 @@ CATEGORY:

OPTIONS:
--verbose, -v print verbose deal details (default: false)
--color use color in display output (default: true)
--color use color in display output (default: depends on output being a TTY)
--show-failed show failed/failing deals (default: false)
--watch watch deal updates in real-time, rather than a one time list (default: false)
--help, -h show help (default: false)
Expand Down Expand Up @@ -747,7 +747,7 @@ CATEGORY:

OPTIONS:
--verbose, -v print verbose transfer details (default: false)
--color use color in display output (default: true)
--color use color in display output (default: depends on output being a TTY)
--completed show completed data transfers (default: false)
--watch watch deal updates in real-time, rather than a one time list (default: false)
--show-failed show failed/cancelled transfers (default: false)
Expand Down