From 6adc6586c115f6ae2d604661959ad8cc9302c19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Andr=C3=A9e?= Date: Sat, 17 Aug 2013 08:18:49 +0200 Subject: [PATCH] whether to use colours in ArgParser.help MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/argparser.py | 7 ++++++- src/ponysay.py | 1 + src/ponysaytool.py | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/argparser.py b/src/argparser.py index 564dae61..d12372c4 100755 --- a/src/argparser.py +++ b/src/argparser.py @@ -245,10 +245,15 @@ class ArgParser(): return self.rc - def help(self): + def help(self, use_colours = None): ''' Prints a colourful help message + + @param use_colours:bool? Whether to use colours, `None` if stdout is not piped ''' + if use_colours is None: + use_colours = sys.stdout.isatty() + print('\033[1m%s\033[21m %s %s' % (self.__program, '-' if self.linuxvt else '—', self.__description)) print() if self.__longdescription is not None: diff --git a/src/ponysay.py b/src/ponysay.py index 875e94d3..979a415e 100755 --- a/src/ponysay.py +++ b/src/ponysay.py @@ -237,6 +237,7 @@ class Ponysay(): ## Run modes if self.__test_nfdnf('-h'): args.help() + elif self.__test_nfdnf('+h'): args.help(True) elif self.__test_nfdnf('-v'): self.version() elif self.__test_nfdnf('--quoters'): self.quoters(True, False) elif self.__test_nfdnf('--Onelist', ('--onelist', '++onelist')): self.onelist(True, True) diff --git a/src/ponysaytool.py b/src/ponysaytool.py index 644886fc..5b6fee3b 100755 --- a/src/ponysaytool.py +++ b/src/ponysaytool.py @@ -85,8 +85,8 @@ class PonysayTool(): opts = args.opts - if unrecognised or (opts['-h'] is not None): - args.help() + if unrecognised or (opts['-h'] is not None) or (opts['+h'] is not None): + args.help(True if opts['+h'] is not None else None) if unrecognised: exit(254)