From bc8682df21255664a6b9f323c23e0f235d91fcd8 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Sat, 30 Apr 2022 20:28:06 +0200 Subject: add a useless continuation char option --- format.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/format.py b/format.py index 7873494..e226a5d 100755 --- a/format.py +++ b/format.py @@ -68,7 +68,8 @@ def wrap_text_block(text, max_width, forbid_dangling_chars=False, return lines -def format_hint(hint, hint_id, langs, max_width=MAX_WIDTH, indent=INDENT): +def format_hint(hint, hint_id, langs, max_width=MAX_WIDTH, indent=INDENT, + continuation_char=' '): lines = [] for lang in langs: @@ -100,6 +101,8 @@ def format_hint(hint, hint_id, langs, max_width=MAX_WIDTH, indent=INDENT): lines.extend(' ' * indent + l for l in block) + lines = [continuation_char + l[1:] if l[0] == ' ' else l for l in lines] + return '\n'.join(lines) hints = json.load((here / 'hints.json').open()) @@ -107,7 +110,9 @@ hints = json.load((here / 'hints.json').open()) @click.command() @click.option('-i', '--hint-id', default='-1', type=click.types.INT, show_default=True, help='which hint to format (-1 for random)') -def main(hint_id): +@click.option('-c', '--continuation-char', default=' ', type=click.types.STRING, + show_default=True, help='how to start indented lines') +def main(hint_id, continuation_char): if hint_id == -1: [(hint_id, hint)] = random.sample([*hints.items()], 1) else: @@ -118,7 +123,8 @@ def main(hint_id): print("No such hint!", file=sys.stderr) return sys.exit(1) - print(format_hint(hint, hint_id, [*hint['name'].keys()])) + print(format_hint(hint, hint_id, [*hint['name'].keys()], + continuation_char=continuation_char[0])) if __name__ == '__main__': main() -- cgit v1.2.3