Bug#742207: codespell: please disable colors when stdout is not terminal

2 views
Skip to first unread message

Jakub Wilk

unread,
Mar 20, 2014, 9:11:28 PM3/20/14
to Debian Bug Tracking System
Package: codespell
Version: 1.6-1
Severity: minor

The description of the -d option suggests that the option is not needed
when you print to a terminal.

$ codespell --help | grep disable-colors
-d, --disable-colors Disable colors even when printing to terminal


But in reality, the option is needed:

$ echo abilty > typo && codespell typo | cat -A
^[[33mtypo^[[0m:^[[33m1^[[0m: ^[[31mabilty^[[0m ==> ^[[32mability^[[0m$

$ echo abilty > typo && codespell -d typo | cat -A
typo:1: abilty ==> ability$


Please disable colors when stdout is not a terminal.

--
Jakub Wilk

Paul Wise

unread,
Mar 20, 2014, 10:37:41 PM3/20/14
to 742...@bugs.debian.org, code...@googlegroups.com, Paul Wise
---
codespell.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/codespell.py b/codespell.py
index fdbd5cb..816593c 100755
--- a/codespell.py
+++ b/codespell.py
@@ -478,7 +478,7 @@ def main(*args):

build_dict(options.dictionary)
colors = TermColors();
- if options.disable_colors:
+ if options.disable_colors or not sys.stdout.isatty():
colors.disable()

if options.summary:
--
1.9.0

Lucas De Marchi

unread,
Mar 21, 2014, 5:57:28 AM3/21/14
to code...@googlegroups.com, 742...@bugs.debian.org, Paul Wise
On Thu, Mar 20, 2014 at 11:37 PM, Paul Wise <pa...@bonedaddy.net> wrote:
> ---
> codespell.py | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/codespell.py b/codespell.py
> index fdbd5cb..816593c 100755
> --- a/codespell.py
> +++ b/codespell.py
> @@ -478,7 +478,7 @@ def main(*args):
>
> build_dict(options.dictionary)
> colors = TermColors();
> - if options.disable_colors:
> + if options.disable_colors or not sys.stdout.isatty():

I think we need a way to disable it by default if it's not a tty, but
not impose it. IMO it's a pain to review big projects without color,
so in general I save to a file and review with less, that is capable
of displaying the colors.

Lucas De Marchi

Paul Wise

unread,
Mar 22, 2014, 2:05:55 AM3/22/14
to 742...@bugs.debian.org, code...@googlegroups.com, Paul Wise
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:

Lucas De Marchi

unread,
Mar 30, 2014, 2:20:27 AM3/30/14
to code...@googlegroups.com, 742...@bugs.debian.org, Paul Wise
On Sat, Mar 22, 2014 at 3:05 AM, Paul Wise <pa...@bonedaddy.net> wrote:
> 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
> ---

Applied. Thanks.

Lucas De Marchi
Reply all
Reply to author
Forward
0 new messages