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

never, auto and always modes for --color switch #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions display.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func init() {
color.Output = colorable.NewColorableStdout()
}

func ForcePrintColor(mode bool) {
color.NoColor = !mode
}

type Displayer interface {
Display([]*html.Node)
}
Expand Down
17 changes: 16 additions & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func PrintHelp(w io.Writer, exitCode int) {
Version
%s
Flags
-c --color print result with color
-c --color [mode] print result with color; mode is never, auto (default), or always
-f --file file to read from
-h --help display this help
-i --indent number of spaces to use for indent or character
Expand Down Expand Up @@ -87,6 +87,21 @@ func ProcessFlags(cmds []string) (nonFlagCmds []string, err error) {
switch cmd {
case "-c", "--color":
pupPrintColor = true
if (i+1) < len(cmds) { // `--color` is not tail arg
switch strings.ToLower(cmds[i+1]) {
case "never":
pupPrintColor = false
ForcePrintColor(false)
i++
case "auto":
// set by default
// see also https://github.com/fatih/color#disableenable-color
i++
case "always":
ForcePrintColor(true)
i++
}
}
case "-p", "--plain":
pupEscapeHTML = false
case "--pre":
Expand Down