never, auto and always modes for --color switch

see #137
pull/157/head
paul 3 years ago
parent 681d7bb639
commit 76da365ad3

@ -16,6 +16,10 @@ func init() {
color.Output = colorable.NewColorableStdout()
}
func ForcePrintColor(mode bool) {
color.NoColor = !mode
}
type Displayer interface {
Display([]*html.Node)
}

@ -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
@ -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":

Loading…
Cancel
Save