mirror of
https://github.com/erkin/ponysay.git
synced 2025-02-16 17:44:23 +01:00
fix issue 117
Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
parent
6adc6586c1
commit
82e3dc3cf5
1 changed files with 28 additions and 12 deletions
|
@ -254,20 +254,29 @@ class ArgParser():
|
|||
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(('\033[1m%s\033[21m %s %s' if use_colours else '%s %s %s') % (self.__program, '-' if self.linuxvt else '—', self.__description))
|
||||
print()
|
||||
if self.__longdescription is not None:
|
||||
print(self.__longdescription)
|
||||
desc = self.__longdescription
|
||||
if not use_colours:
|
||||
while '\033' in desc:
|
||||
esc = desc.find('\033')
|
||||
desc = desc[:esc] + desc[desc.find('m', esc) + 1:]
|
||||
print(desc)
|
||||
print()
|
||||
|
||||
print('\033[1mUSAGE:\033[21m', end='')
|
||||
print('\033[1mUSAGE:\033[21m' if use_colours else 'USAGE:', end='')
|
||||
first = True
|
||||
for line in self.__usage.split('\n'):
|
||||
if first:
|
||||
first = False
|
||||
else:
|
||||
print(' or', end='')
|
||||
print('\t%s' % (line))
|
||||
if not use_colours:
|
||||
while '\033' in line:
|
||||
esc = line.find('\033')
|
||||
line = line[:esc] + line[line.find('m', esc) + 1:]
|
||||
print('\t%s' % line)
|
||||
print()
|
||||
|
||||
maxfirstlen = []
|
||||
|
@ -282,7 +291,7 @@ class ArgParser():
|
|||
maxfirstlen.append(first)
|
||||
maxfirstlen = len(max(maxfirstlen, key = len))
|
||||
|
||||
print('\033[1mSYNOPSIS:\033[21m')
|
||||
print('\033[1mSYNOPSIS:\033[21m' if use_colours else 'SYNOPSIS')
|
||||
(lines, lens) = ([], [])
|
||||
for opt in self.__arguments:
|
||||
opt_type = opt[0]
|
||||
|
@ -300,10 +309,17 @@ class ArgParser():
|
|||
if opt_alt is alts[-1]:
|
||||
line += '%colour%' + opt_alt
|
||||
l += len(opt_alt)
|
||||
if opt_type == ARGUMENTED: line += ' \033[4m%s\033[24m' % (opt_arg); l += len(opt_arg) + 1
|
||||
elif opt_type == VARIADIC: line += ' [\033[4m%s\033[24m...]' % (opt_arg); l += len(opt_arg) + 6
|
||||
if use_colours:
|
||||
if opt_type == ARGUMENTED: line += ' \033[4m%s\033[24m' % (opt_arg); l += len(opt_arg) + 1
|
||||
elif opt_type == VARIADIC: line += ' [\033[4m%s\033[24m...]' % (opt_arg); l += len(opt_arg) + 6
|
||||
else:
|
||||
if opt_type == ARGUMENTED: line += ' %s' % (opt_arg); l += len(opt_arg) + 1
|
||||
elif opt_type == VARIADIC: line += ' [%s...]' % (opt_arg); l += len(opt_arg) + 6
|
||||
else:
|
||||
line += ' \033[2m%s\033[22m ' % (opt_alt)
|
||||
if use_colours:
|
||||
line += ' \033[2m%s\033[22m ' % (opt_alt)
|
||||
else:
|
||||
line += ' %s ' % (opt_alt)
|
||||
l += len(opt_alt) + 6
|
||||
lines.append(line)
|
||||
lens.append(l)
|
||||
|
@ -316,14 +332,14 @@ class ArgParser():
|
|||
if opt_help is None:
|
||||
continue
|
||||
first = True
|
||||
colour = '36' if (index & 1) == 0 else '34'
|
||||
print(lines[index].replace('%colour%', '\033[%s;1m' % (colour)), end=' ' * (col - lens[index]))
|
||||
colour = ('36' if (index & 1) == 0 else '34') if use_colours else ''
|
||||
print(lines[index].replace('%colour%', ('\033[%s;1m' % colour) if use_colours else ''), end=' ' * (col - lens[index]))
|
||||
for line in opt_help.split('\n'):
|
||||
if first:
|
||||
first = False
|
||||
print('%s' % (line), end='\033[21;39m\n')
|
||||
print('%s' % (line), end='\033[21;39m\n' if use_colours else '\n')
|
||||
else:
|
||||
print('%s\033[%sm%s\033[39m' % (' ' * col, colour, line))
|
||||
print(('%s\033[%sm%s\033[39m' if use_colours else '%s%s%s') % (' ' * col, colour, line))
|
||||
index += 1
|
||||
|
||||
print()
|
||||
|
|
Loading…
Reference in a new issue