Skip to content

Commit

Permalink
fix nimgrep color on posix #7591 (#12288)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-mr authored and Araq committed Sep 27, 2019
1 parent f804245 commit 5a65243
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tools/nimgrep.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Options:
--ignoreCase, -i be case insensitive
--ignoreStyle, -y be style insensitive
--ext:EX1|EX2|... only search the files with the given extension(s)
--nocolor output will be given without any colours.
--nocolor output will be given without any colours
--color[:always] force color even if output is redirected
--group group matches by file
--verbose be verbose: list every processed file
--filenames find the pattern in the filenames, not in the contents
Expand Down Expand Up @@ -270,6 +271,10 @@ proc checkOptions(subset: TOptions, a, b: string) =
if subset <= options:
quit("cannot specify both '$#' and '$#'" % [a, b])

when defined(posix):
useWriteStyled = terminal.isatty(stdout)
# that should be before option processing to allow override of useWriteStyled

oneline = true
for kind, key, val in getopt():
case kind
Expand Down Expand Up @@ -304,6 +309,12 @@ for kind, key, val in getopt():
of "ignorestyle", "y": incl(options, optIgnoreStyle)
of "ext": extensions.add val.split('|')
of "nocolor": useWriteStyled = false
of "color":
case val
of "auto": discard
of "never", "false": useWriteStyled = false
of "", "always", "true": useWriteStyled = true
else: writeHelp()
of "oneline": oneline = true
of "group": oneline = false
of "verbose": incl(options, optVerbose)
Expand All @@ -313,9 +324,6 @@ for kind, key, val in getopt():
else: writeHelp()
of cmdEnd: assert(false) # cannot happen

when defined(posix):
useWriteStyled = terminal.isatty(stdout)

checkOptions({optFind, optReplace}, "find", "replace")
checkOptions({optPeg, optRegex}, "peg", "re")
checkOptions({optIgnoreCase, optIgnoreStyle}, "ignore_case", "ignore_style")
Expand Down

0 comments on commit 5a65243

Please sign in to comment.