-
Notifications
You must be signed in to change notification settings - Fork 411
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
Option to set the background extension mode to ANSI or spaces #512
Conversation
ba9c5f4
to
306621b
Compare
@th1000s can you explain why we ever need to fill with spaces? Sorry if I'm being slow! I don't think I've understood the motivation for this PR. I see this problem:
|
No problem. Hereafter "ANSI" means the ANSI Sequence which extends the color until the end of the line. So, ANSI placed after the truncation symbol is the problem [1] (adapted from your screenshot), ANSI placed on lines which are not cut off is fine [2]. But, just selectively skipping ANSI at e.g. [3] but still emitting it where the line is not cut of [5] would result in a jagged right edge, here crossed out in red. Not using ANSI or spaces doesn't work either, because then the cut off lines are fine [3], but shorter lines are not [4]. This means the only option is to not use ANSI for truncated lines, and filling up lines which are too short with spaces, i.e. [3] and [5] up to the dotted line. |
Thanks very much for explaining that carefully. Would another alternative be to place the continuation character on the green (or whatever) background color instead of on the default (here white) background color? I was thinking that would then allow the code to be almost unchanged, with ANSI sequences used on all lines to fill the background color to the terminal width. |
Continuing my comment above, here are a couple of screenshots (on this branch at 306621b). Please correct me if I'm wrong but what I'm thinking is that even with this plan:
we are still going to get "jagged right edges" in a sense, because the column to which the right fill extends will vary between files and diff hunks. Hence my question about whether we should consider just placing everything, including the continuation character, on the colored background and always filling rightwards to the maximum extent, using the ANSI sequence in the right panel.
|
Yes, making the background of a continuation character (
For larger visual component these are still there, that is true. But back to the initial issue, for my personal taste the inconsistency of having the background always end with exactly the last character on the red/left side, but having it extend further on the right side is worse - hence my initial fix of always padding with spaces. And while this ruins terminal resizing/shrinking, in side-by-side mode that is going to happen much sooner anyhow. To help with that, maybe the pager could be started with |
I'm still not sure about this (in the sense that I'm genuinely not sure, not a euphemism for being against!). One consideration is that we haven't had any complaints from other users, and also this was the explicit motivation for the ANSI code in the first place. Is it possible for this decision to be made independently of adding the |
No problem, I'll adjust the background color of the continuation character to match that of the rest of the line. I'd also want to set the foreground color to blue to remove any possible ambiguities and still have it stand out a bit, similar how vim can highlight non-printable characters. Blue seems to be quite readable on both dark and light backgrounds (maybe tab-highlighting can work that way in delta as well). As for the for the ANSI code motivation, my impression was that these were more relevant for the unified diff view and were then re-used for the right panel of the side-by-side mode. |
Great. Regarding the spaces vs ANSI I am worried about causing you unnecessary work in the event that we both agree in the end that spaces is the right solution! So please, if you feel it makes sense to finish the conversation above before altering code, that would be absolutely fine of course.
That sounds good.
Right. Perhaps we'll want to make that color user-customizable? Side-by-side users will see it a lot (and delta seems to have taken it upon itself to be customizable to the last degree!) |
Indeed, the right padding is either 1 or 2, never 0 or 1, I thought it was a stylistic choice and never questioned it :) If at most 1 line of padding is the goal, maybe that can be inserted in the middle, before the right line-numbers. That would make all the issues here disappear.
This patchset already makes using spaces or ANSI a function parameter (
Of course. The same goes for the continuation/termination chars, maybe someone likes other symbols more or wants to only use 7-bit ASCII. |
This sounds great. There is one thing that we need to bear in mind. Basically, I think that the fact that delta's width calculations are leaving extra columns on the right is due to this line: Lines 517 to 518 in e7d1e28
I just wanted to highlight that line of code. Everything that follows in the rest of this comment is detail, just in case it is helpful. The issue being addressed there is that To understand the history, the best issue to look at is this one: #115, which led to delta switching to use the ANSI fill-color-right sequence instead of manually padding with spaces. But that still leaves the issue for things like horizontal dividing lines, hence the I think it may be relevant to mention that bat has a solution for this that we could consider introducing to delta. Bat's solution is to allow the user to declare how many columns are available to the application (bat/delta) via a +/- offset:
See sharkdp/bat@dda27b2 and sharkdp/bat#376. |
I suspected there was a history to that behavior. Also, well, it is broken again, or maybe never worked with side-by-side mode: |
f520ac7
to
63c01dd
Compare
63c01dd
to
36873d2
Compare
PanelSide::Right => &mut self.right, | ||
} | ||
} | ||
} |
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.
Very nice. Thanks, I didn't know about these traits.
src/features/line_numbers.rs
Outdated
@@ -7,6 +7,8 @@ use crate::config; | |||
use crate::delta::State; | |||
use crate::features::hyperlinks; | |||
use crate::features::side_by_side; | |||
use crate::features::side_by_side::LeftRight; | |||
use crate::features::side_by_side::PanelSide::{Left, Right}; |
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.
Since Left
and Right
and LeftRight
are used here in line_numbers.rs
, I think that raises the questions:
- Should they be called
Minus
andPlus
rather thanLeft
andRight
? (because they are used in contexts other than side-by-side, and because the rest of the codebase uses "minus" and plus" with this meaning) - Should they be defined somewhere more central than
side-by-side.rs
?
However, even if those questions are reasonable, I am happy to leave them unresolved for now and let you decide in the main side-by-side PR. Actually, probably good to resolve this question now.
plus_line_diff_style_sections, | ||
); |
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.
If "left" basically means the same thing as "minus" here, then the two sets of equivalent variable names here are making this code harder to understand. I'll wait for your opinion on this topic before merging this PR.
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.
This looks fantastic, I really appreciate the refactoring and data structures introduced to make the code clearer and more compact.
I'm just marking this "request changes" because I have that question about whether "left/right" and "minus/plus" have genuinely distinct semantics, or whether we can simplify to use "minus/plus" in the situations where we have a data structure holding data from removed and added lines respectively (which, if side-by-side is active will be destined for left and right panels respectively).
Here is my attempt to have my cake and eat it too: The data structure is now I can now squash this as-is into the previous commits or drop the |
Great, thanks!
I'd like to squash and keep the Left/Right indexing. Looks like some tests are failing now, but once you've squashed and CI is green, I'll merge this.
|
Can be indexed with Minus/Plus or in a side-by-side context with Left/Right to represent the left/right Panels.
In side-by-side mode, if `background_color_extends_to_terminal_width` is set, the left panel color is extended via spaces, but the right one via an ANSI sequence which instructs the terminal emulator to fill the background color rightwards. The command line option --line-fill-method ansi|spaces can change how the right panel background is filled. Add enums `BgShouldFill` and `BgFillMethod` to better distinguish if the background should be filled, and if so, how.
d14116f
to
3e50118
Compare
Ah, I mean the other left of course, should be fixed! |
Merged -- thanks very much for this work @th1000s, and I'm really looking forward to having the new wrapping |
(Original topic: Fix right panel background extending beyond the truncation symbol)
In side-by-side mode, if
background_color_extends_to_terminal_width
is set, the left panel color is extended via spaces, but the right
one via an ANSI sequence which instructs the terminal emulator to
fill the background color rightwards.
However due to the padding after the right panel the color will
extend beyond a possible truncation symbol:
TEXT#AB→#
, notTEXT#AB→
with#
being the green background.This is fixed by using the same logic as in the left panel for the
right panel.
Before-After comparison in Konsole: