-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add block bar #361
Add block bar #361
Conversation
Codecov Report
@@ Coverage Diff @@
## master #361 +/- ##
=======================================
Coverage 99.11% 99.12%
=======================================
Files 50 51 +1
Lines 4308 4357 +49
=======================================
+ Hits 4270 4319 +49
Misses 38 38
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Bravo for attempting this. It might be a mistake to duplicate some of the arguments from the progress bar. I can see this being a more general purpose thing, which would have different uses beyond progress. I'm thinking it should have a width (in cells), plus a start and end argument as a float (which could be internally converted to 1/8ths). Plus a foreground and background color. You're absolutely correct that there are only left aligned block characters. But flip the foreground and background colors, and you have the equivalent of right aligned. :-) |
rich/bar.py
Outdated
style: StyleType = "bar.back", | ||
complete_style: StyleType = "bar.complete", | ||
finished_style: StyleType = "bar.finished", | ||
blend_colors: bool = False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we probably don't want to implement blending here. This class could be a primitive that you could extend to add the blend functionality.
It should probably use colors, rather than styles. Since much of the attributes (italic / bold) etc don't make sense for a solid bar.
Here's what I'm thinking for the constructor:
width: Optional[float], # Number of cells to use, or None for full width
size: float, # Value for end of the bar
start: float, # Start point (in 0 -> size units)
end: float, # End point
color: Union[Color, str] = "default",
background: Union[Color, str] = "default",
A union for the colors, so you can pass a Color or a string to call Color.parse with.
What do you think?
That's a nice trick @willmcgugan! I got it working. But in my iTerm, if I set some non-zero window transparency, the background color from the flipped Style looks faded compared to the foreground color from the non-flipped Style, unless I set checkbox "Keep background colors opaque". Is there anything I can do? 🤔 Also, how can I flip colors in case they are both |
Ah that's a shame. There is an "right half block" character (▐) . You could have the 1/8 granularity for the right hand side of the bar, and the 1/2 block granularity for the left.
Good point. If we don't use the flipping colors trick and use the right half block, then this won't be an issue. Alternatively we could disallow default colors for the bar, and document the transparency issue. I'll leave it up to you. BTW would love to see screenshots! |
Just had a thought. Rather than swap the foreground / background manually, what if you were to set |
Would you mind also adding an example in Something very simple, a few lines that show how you might use it in practice. |
@willmcgugan I would go with a 1/2 granularity on the left side 😌 (actually there is also right-aligned 1/8 block character, so there's a choice of three characters: 1/8, 1/2, full). Added the example too! |
Thanks @megaserg This looks great. I'll merge this soon. |
Thanks @megaserg ! |
Type of changes
Checklist
Description
This implements a solid block bar, as requested in #293.
Try with:
python -m rich.block_bar
Implemented:
Not implemented:
Note:
BlockBar
might not be the best name. Let me know!