Skip to content

Commit

Permalink
Respect GOLOG_LOG_FMT=color
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi committed Jul 8, 2021
1 parent 140a2e0 commit 4dd59b5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cli/util/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ import (
"github.com/mattn/go-isatty"
)

var DefaultColorUse = isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())
// 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())

5 comments on commit 4dd59b5

@stuberman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW @ribasushi I updated my code for all of these commits yesterday.
When I run CLI commands I see the color, but now with watch I lost all of the colors...

colors gone

@ribasushi
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stuberman sigh... there are two color specifications in this command flow:

As a result

lotus-miner --color=1 actor control list 2>&1 | cat

doesn't do what you want, while

lotus-miner actor control list --color=1 2>&1 | cat

will do so.

I don't think we can easily unify the flags because it will break for folks who do specify the flag... @magik6k would have to chime in.

As a general workflow that will work everywhere you can use the very code you commented on:

GOLOG_LOG_FMT=color watch -c -- lotus-miner actor control list

will do exactly what you want

@stuberman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick response.

My point is that after these commits when I use watch the colors no longer show up regardless of the color flag

colors missing

@stuberman
Copy link

@stuberman stuberman commented on 4dd59b5 Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now when I prepend GOLOG_LOG_FMT=color everything looks good again

@ribasushi
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that after these commits when I use watch the colors no longer show up

This is by design

regardless of the color flag

This is inaccurate: please look at the --color position carefully in the 2 examples here: 4dd59b5#commitcomment-53382350

Please sign in to comment.