Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

only colourize text if the output is a tty.

  • Loading branch information...
commit 53ec39c6cbd3c8c8e1ab52a29eef8ef4fb463aaa 1 parent 58c7903
@mnot mnot authored
Showing with 21 additions and 23 deletions.
  1. +2 −1  bin/redbot
  2. +19 −22 redbot/formatter/text.py
View
3  bin/redbot
@@ -79,7 +79,8 @@ def main():
)
formatter = find_formatter(options.output_format, 'txt', options.descend)(
- sys.argv[0], url, [], lang, output
+ sys.argv[0], url, [], lang, output,
+ tty_out = sys.stdout.isatty()
)
formatter.set_red(red.state)
formatter.start_output()
View
41 redbot/formatter/text.py
@@ -115,29 +115,26 @@ def format_recommendation(self, red, category):
out.append(nl)
return nl.join(out)
- @staticmethod
- def colorize(level, string):
- # info
- color_start = u"\033[0;32m"
- color_end = u"\033[0;39m"
-
- if level == "good":
- color_start = u"\033[1;32m"
+ def colorize(self, level, string):
+ if self.kw.get('tty_out', False):
+ # info
+ color_start = u"\033[0;32m"
color_end = u"\033[0;39m"
-
- if level == "bad":
- color_start = u"\033[1;31m"
- color_end = u"\033[0;39m"
-
- if level == "warning":
- color_start = u"\033[1;33m"
- color_end = u"\033[0;39m"
-
- if level == "uri":
- color_start = u"\033[1;34m"
- color_end = u"\033[0;39m"
-
- return color_start + string + color_end
+ if level == "good":
+ color_start = u"\033[1;32m"
+ color_end = u"\033[0;39m"
+ if level == "bad":
+ color_start = u"\033[1;31m"
+ color_end = u"\033[0;39m"
+ if level == "warning":
+ color_start = u"\033[1;33m"
+ color_end = u"\033[0;39m"
+ if level == "uri":
+ color_start = u"\033[1;34m"
+ color_end = u"\033[0;39m"
+ return color_start + string + color_end
+ else:
+ return string
Please sign in to comment.
Something went wrong with that request. Please try again.