commit 8594a7ebfe7cb6fd2f8be4c1aaf5512609dbd1a3
parent d8c694d2766f4ed56cf57294696edc4f3e28ac49
Author: Isak Lindhé <isak.lindhe@ne.se>
Date: Sun, 16 Jun 2019 19:47:21 +0200
fancy help formatting
Diffstat:
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/txtv/txtv.py b/txtv/txtv.py
@@ -118,19 +118,25 @@ def interactive(start_page: Page):
#####################
def cmd_help(**kwargs) -> str:
- out = 'commands:\n'
+ def helpname(cmd: dict):
+ '''Returns the name to show in the help text.'''
+ if 'helpname' in cmd:
+ return cmd['helpname']
+ else:
+ return re.sub(r'\|', r' | ', cmd['pattern'])
+
+ out = Style.BRIGHT + Fore.YELLOW + 'Commands:' + Style.RESET_ALL + '\n'
for cmd in commands:
if 'help' in cmd:
- if 'helpname' in cmd:
- name = cmd['helpname']
- else:
- name = cmd['pattern']
- name = re.sub(r'\|', r' | ', name)
- out += ('{} -- {}{}\n'.format(
+ name = helpname(cmd)
+ out += ('{}{} {}-- {}{}{}\n'.format(
name,
+ ' '*(max(len(helpname(cmd)) for cmd in commands) - len(name)),
+ Style.DIM,
cmd['help'],
' (only in interactive mode)'
- if 'interactive_only' in cmd and cmd['interactive_only'] else ''
+ if 'interactive_only' in cmd and cmd['interactive_only'] else '',
+ Style.RESET_ALL
))
return out