Disable colours when stdout is not a terminal by default.
Add an option to enable colours when stdout is not a terminal.
Fixes:
https://bugs.debian.org/742207
---
codespell.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/codespell.py b/codespell.py
index fdbd5cb..1fd8409 100755
--- a/codespell.py
+++ b/codespell.py
@@ -189,9 +189,13 @@ class FileOpener:
def parse_options(args):
parser = OptionParser(usage=USAGE, version=VERSION)
+ parser.set_defaults(colors = sys.stdout.isatty())
parser.add_option('-d', '--disable-colors',
- action = 'store_true', default = False,
+ action = 'store_false', dest = 'colors',
help = 'Disable colors even when printing to terminal')
+ parser.add_option('-c', '--enable-colors',
+ action = 'store_true', dest = 'colors',
+ help = 'Enable colors even when not printing to terminal')
parser.add_option('-w', '--write-changes',
action = 'store_true', default = False,
help = 'write changes in place if possible')
@@ -478,7 +482,7 @@ def main(*args):
build_dict(options.dictionary)
colors = TermColors();
- if options.disable_colors:
+ if not options.colors: