-
-
Save duckinator/ca034878ab83322bd9b3da1422ead4f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/test$ printf " a\n b\n c\n" | |
a | |
b | |
c | |
~/test$ printf " a\n b\n c\n" | python3 -m textwrap-tool dedent | |
a | |
b | |
c | |
~/test$ printf " a\n b\n c\n" | python3 -m textwrap-tool indent '....' | |
.... a | |
.... b | |
.... c | |
~/test$ printf "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | python3 -m textwrap-tool wrap 10 | |
1234567890 | |
abcdefghij | |
klmnopqrst | |
uvwxyzABCD | |
EFGHIJKLMN | |
OPQRSTUVWX | |
YZ | |
~/test$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from textwrap import wrap, fill, shorten, dedent, indent | |
args = sys.argv[2:] | |
if len(args) > 0 and sys.argv[1] in ['wrap', 'fill', 'shorten']: | |
args[0] = int(args[0]) | |
fns = {'wrap': wrap, 'fill': fill, 'shorten': shorten, 'dedent': dedent, 'indent': indent} | |
ret = fns[sys.argv[1]](sys.stdin.read(), *args) | |
if isinstance(ret, list): | |
# Handle things like wrap(), which returns a list. | |
print('\n'.join(ret)) | |
else: | |
print(ret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment