-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display help message in multi-line format? #555
Comments
According to the code which handles it, it seems it does not assume multiline help messages: plumbum/plumbum/cli/application.py Lines 930 to 953 in 3876425
|
Probably could be fixed, PR welcome. |
@henryiii @tashrifbillah here's what I've come up with. I could do the PR but ETA is unspecified (otherwise let someone go ahead) first, let's split the text by line breaks: >>> text = "This is first paragraph, of average length.\n" \
... "And this is the second one.\n" \
... "That's the longest paragraph, you can see it yourself."
>>> stext = text.splitlines()
>>> stext
['This is first paragraph, of average length.', 'And this is the second one.', "That's the longest paragraph, you can see it yourself."] now, wrap the previous stage' result using >>> stext=text.splitlines()
>>> list(map(TextWrapper(width=15).wrap, stext))
[['This is first', 'paragraph, of', 'average length.'], ['And this is the', 'second one.'], ["That's the", 'longest', 'paragraph, you', 'can see it', 'yourself.']] finally, lets create wrap() function which will also flatten the list and join it using specified indent: >>> from textwrap import TextWrapper
>>> from typing import List
>>>
>>>
>>> def wrap(text: str, max_width: int, indent_size: int = 4):
... indent=' ' * indent_size
... return '\n'.join([
... line for lst in map(
... TextWrapper(width=max_width,
... initial_indent=indent,
... subsequent_indent=indent).wrap,
... text.splitlines()
... )
... for line in lst
... ])
...
>>>
>>> text = """
... This is first paragraph, of average length.\n
... And this is the second one.\n
... That's the longest paragraph, you can see it yourself.
... """
>>>
>>> print(wrap(text, max_width=15), '\n')
This is
first
paragraph,
of average
length.
And this is
the second
one.
That's the
longest
paragraph,
you can see
it
yourself.
>>> print(wrap(text, max_width=80, indent_size=8))
This is first paragraph, of average length.
And this is the second one.
That's the longest paragraph, you can see it yourself. |
Hi, I shall try to do it myself. I have marked the email notification. |
Hi @ink-splatters , sorry about the delay--the idea that you came up with, should it be inserted before line 931? |
I inserted this block: # break and join multi-line help message
max_width= 200
indent_size= 8
indent=' ' * indent_size
help= '\n'.join([
line for lst in map(
TextWrapper(width=max_width,
initial_indent=indent,
subsequent_indent=indent).wrap,
help.splitlines()
)
for line in lst
]) after line 931 but no effect. I believe this block joins them back together :( plumbum/plumbum/cli/application.py Lines 945 to 947 in 0c574a9
|
Replacing the latter block with
I see that the second and third lines of my help message do not follow the indent of first line but it is some progress :) Please let me know how we can improve upon it. |
Hi @tashrifbillah, I was completely incapable to answer on time, sorry for that, as well as contributing more, by personal reasons. It will likely change, probably soon. Thanks a lot |
Way to reproduce
multi_line.py
Expected
As I wrote in the program:
--imain VALUE:str primary4D,secondary4D/3D primary: one 4D volume input, should be PA; secondary: another 3D/4D volume input, should be AP, which is opposite of primary 4D volume
Actual
Spanning across my terminal in an untidy way:
Is the expected at all possible?
The text was updated successfully, but these errors were encountered: