whether to use colours in ArgParser.help

Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
Mattias Andrée 2013-08-17 08:18:49 +02:00
parent 0ce6f62c0b
commit 6adc6586c1
3 changed files with 9 additions and 3 deletions

View file

@ -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:

View file

@ -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)

View file

@ -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)