Skip to content
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

[REQUEST] support multiple chars for rule printing #204

Closed
hedyhli opened this issue Aug 4, 2020 · 6 comments · Fixed by #207
Closed

[REQUEST] support multiple chars for rule printing #204

hedyhli opened this issue Aug 4, 2020 · 6 comments · Fixed by #207
Assignees
Labels
accepted Task was accepted

Comments

@hedyhli
Copy link
Contributor

hedyhli commented Aug 4, 2020

Have you checked the issues for a similar suggestions? Yes

How would you improve Rich?

Currently for rule.py it only allows the character to have 1 cell length, it would better if it could allow more, like

>>> console.print(Rule("hello", character="-+"))
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ hello -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

What problem does it solved for you?

I was just thinking it would improve it and it looks like an ASCII rule, which is cool (like this program)


If this is accepted, I would like to work on it, because I have already tried it out ”locally” (https://repl.it/@hedythedev/rich#rich/rule.py) and it works well

console.print(Rule(text, character="-/-"))

BDB784D3-8BA2-4978-9791-6860EEFE0384

@hedyhli
Copy link
Contributor Author

hedyhli commented Aug 4, 2020

I will also remember add tests for this (if accepted) of course

@hedyhli hedyhli changed the title [REQUEST] support for multiple chars for rule printing [REQUEST] support multiple chars for rule printing Aug 4, 2020
@willmcgugan willmcgugan added accepted Task was accepted and removed Needs triage labels Aug 4, 2020
@willmcgugan
Copy link
Collaborator

Hi @hedythedev

Works for me. Since we allow multiple characters now, it should probably take in to account multi-cell characters like emoji. See the functions in cells.py for help with that.

The name of the parameter is probably wrong now. character implies a single character. Suggest adding additional characters parameter which allows for multiple characters.

BTW there is a rule method on the Console class that will also need updating...

Thanks!

@hedyhli
Copy link
Contributor Author

hedyhli commented Aug 4, 2020

Got it!
Btw when you say works for me, do you mean the code in repl.it?

Also would chars work better? Because characters is a bit long

@willmcgugan
Copy link
Collaborator

Btw when you say works for me, do you mean the code in repl.it?

Just meant its a good idea in general.

Also would chars work better? Because characters is a bit long

It is, but I dislike abbreviations. I'd rather type it in full than recall how it was abbreviated...

@hedyhli
Copy link
Contributor Author

hedyhli commented Aug 4, 2020

So if the characters provided have a long length, this might end up happening (| represents terminal width)

>>> console.print(Rule("hello", character="12345"))
|12345 hello 12345    |
#                 ^^^^

Because 12345 is longer than the width left after the right side of 12345, there will be a number blank spaces smaller than the cell width of characters param, in this case it is len(“12345”) == 5. Which is caused by treating characters (12345) as a whole.

So in this case, which solution would we want?

  1. using truncate() to make it
    |1234512 hello 1234512 | (there will be an ending space if length of characters is odd)

  2. Or just leave it as is

|12345 hello 12345    |

In my opinion we should use truncate

@willmcgugan
Copy link
Collaborator

The Rule should extend to the full width available, which may mean you need an extra character on the right hand side. To use your example:

|1234512 hello 12345123|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Task was accepted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants