summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-04-30 20:28:06 +0200
committerWojtek Kosior <koszko@koszko.org>2022-04-30 20:28:06 +0200
commitbc8682df21255664a6b9f323c23e0f235d91fcd8 (patch)
tree4c8812dbd6b60eea21493fededb890f2707c19b4
parentb3c0f821cf03daa79be4cf57e79f6428acd38177 (diff)
downloaddigital-freedom-hints-bc8682df21255664a6b9f323c23e0f235d91fcd8.tar.gz
digital-freedom-hints-bc8682df21255664a6b9f323c23e0f235d91fcd8.zip
add a useless continuation char option
-rwxr-xr-xformat.py12
1 files 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()