added license info to boxprint

master
Kevin Froman 2020-02-08 17:07:39 -06:00
parent 982ac88a72
commit dee531fd51
1 changed files with 10 additions and 2 deletions

View File

@ -1,8 +1,16 @@
def bordered(text): """Add box around string.
taken from https://stackoverflow.com/a/20757491 under https://creativecommons.org/licenses/by-sa/4.0/
https://stackoverflow.com/users/816449/bunyk
"""
def bordered(text: str) -> str:
"""Add border to string."""
lines = text.splitlines() lines = text.splitlines()
width = max(len(s) for s in lines) width = max(len(s) for s in lines)
res = ['' + '' * width + ''] res = ['' + '' * width + '']
for s in lines: for s in lines:
res.append('' + (s + ' ' * width)[:width] + '') res.append('' + (s + ' ' * width)[:width] + '')
res.append('' + '' * width + '') res.append('' + '' * width + '')
return '\n'.join(res) return '\n'.join(res)