-
Notifications
You must be signed in to change notification settings - Fork 243
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
Fix bar-less text output #659
Conversation
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.
Thanks for trying to improve this code. Especially because this is pretty gnarly code, it would be good to split these changes into smaller commits that make minimal (logical) changes -- for example, might introduce the LineType
enum while representing only the types of lines that are currently in lines, and then later introduce the other variants.
src/draw_target.rs
Outdated
.filter(|l| matches!(l, LineType::Text(_))) | ||
.map(|l| String::from(l.as_ref())), |
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.
Suggest we use filter_map()
instead of filter().map()
. Also prefer to_owned()
instead of String::from()
here.
src/draw_target.rs
Outdated
@@ -456,15 +461,60 @@ impl RateLimiter { | |||
|
|||
const MAX_BURST: u8 = 20; | |||
|
|||
#[derive(Debug, Clone, PartialEq)] |
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.
We have a top-down order here, this should move down below any types that rely on it (DrawState
at least).
src/draw_target.rs
Outdated
@@ -473,21 +523,25 @@ pub(crate) struct DrawState { | |||
|
|||
impl DrawState { | |||
fn draw_to_term( | |||
&mut self, | |||
&self, |
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.
Why does this happen?
Thank you for taking the time to review this. My tests omitted the |
Thanks! Force pushing is fine IME. |
Lines 554 to 556 in 5396704
I think my main issue stems here. For wrapping lines, this calculation is not accurate. However the concept itself seems strange to me. Why fill the line with whitespace and expect the terminal to wrap instead of moving the cursor down when needed ? This means when resizing the terminal the formatting will fall apart. Any objections to me investigating changing this behaviour ? |
506bb01
to
1b29cf0
Compare
The new commit passes all the tests but two, and that is because the filler is not only printed when needed (removing one variable definition). On my machine:
|
I never have objections to other people investigating things. 😄 Suggest reading git blame to figure out why this change was made, pretty sure it wasn't just for funsies. |
Removing the empty writes from the test seems fine to me. |
I believe this is working in tandem with this check: Lines 549 to 551 in 5396704
This means that for everyline line other than the first one, a newline is added. The first is expected to wrap automatically due to the filler set in my previous comment. |
This effectively fixes #447. I deeply want to keep going, because there is a lot of further refactoring that can be done, and the current solution of padding the last line will break any resizing. This is, for future reference, the watermark to go back to if the PR spins out of control |
c1b6c0f
to
8c7038e
Compare
In a rare moment of lucidity I will not change the line padding in this PR. It is now ready for review again @djc ! |
62a7eea
to
1433812
Compare
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.
Thanks, this is a lot easier to review!
1433812
to
c7001af
Compare
Resolved most of the comments. For the separate commits, I am very sorry but I do not have infinite time to alter commits of code that gets optimized out in the full PR. I do not think it alters readability either. |
Alright, thanks for all your work on this! |
Thank you, it was a pleasure, I just am travelling a lot at the moment. Cheers ! |
This is my attempt at fixing #447.
The code in
draw_to_term
is a bit of mess, with double definitions, complex branching, and I tried cleaning it up. I introduce aLineType
enum to differentiate between text, bars and empty lines. The variables names have been renamed to reflect better what they represent. Some code has been shuffled around. Tests pass and I ran examples at random with no issues.A sample program to understand what this PR wants to fix:
This is the output of the above before the PR: