-
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
Add side-by-side line wrapping mode #515
Conversation
Thank you, this looks ace ! I've just checked out your PR and am building it right now to do some testing :) |
And @Kr1ss-XD, thanks for reviewing and testing also. |
@Kr1ss-XD Thank you for testing, I somehow managed to overlook that. It is fixed now. @dandavison Yes, the other PR is a stand-alone bug fix, though I noticed the issue while working on this one. |
@th1000s thanks again for the very significant contribution you've made. This question applies to both #512 and this PR, but maybe it'll help to keep the discussion here in the big PR. I was thinking that right-filling with a terminal emulator instruction was an improvement because the user can resize the screen width and the color will expand/contract automatically. If I'm understanding correctly, in #512 you switch to hard-padding with spaces in the right panel, and I may not have fully understood the nature of the problem you're addressing in #512 but here's my question with my current level of understanding: is it possible to have the best of both worlds, i.e. fill right with terminal emulator colors instead of hard spaces, and yet avoid the problem you're addressing in #512? (Would explicitly painting the background color of the continuation character do the trick?) master
this branch
|
Ah, thank you, now I understand the reasoning behind the ANSI sequence. Only emitting color-filling when the line is not wider than the panel would help with the green background highlighting extending beyond it. However this would result in shorter lines still having their highlighting extend beyond the panel, resulting in a jagged right edge: But since these +/- lines are processed as one block, padding with spaces or with color-filling could depend on there being one or more lines which touch the right edge. Any plus-block containing a right-edge-touching line would stand out a bit (feature!) and not wrap nicely on terminal resizes, but otherwise have a consistent look.
I haven't given this detail much thought, I just picked the first angled arrow I found :) But this might combine nicely with adding alignment to the wrapped line. Most of the time just a few characters do not fit onto the line (as visible in Kr1ss' screenshot). These could be right aligned and be marked with When the wrapped line is wider, then it starts all the way on the left again, indicated by e.g. Two different wrapping symbols are a less obtrusive way to indicate a different alignment than writing Also and FYI, the truncation symbol is inverted to indicate that some information was lost, which wrapping should actually prevent. |
Hi @th1000s, I just want to check that you're not waiting for anything from me. I'm thinking that the next step here is that you're planning to rework the #512 changes to use the ANSI sequence, does that sound right? And possibly also some work on the alignment details and continuation characters as you describe above. For my part, I will review the code more, and at some point start a discussion in this thread about what the defaults should be and whether the new code can basically replace the old (but that needn't block the ANSI sequence and alignment details work). |
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 haven't reviewed all the code yet but here are some thoughts on the bit that I've been through so far. It's really nice work, and I really appreciate you having grappled with one of the most complex parts of the codebase.
I'd vote for renaming |
I think that users will basically prefer the new behavior as the default, rather than the old. If we expose |
src/features/wrap.rs
Outdated
|
||
let (minus_start, extended_to) = wrap_text_and_style( | ||
&mut new_minus, | ||
minus_iter.next().expect("bad alignment l (-)"), |
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 this is going to sound a bit odd, but would you mind using unwrap_or_else(|| panic!(...))
instead of expect()
? It's a local style rule that I've been following.
I'm prepared to be shouted down :), but the reason is that I personally really dislike the idiom .expect("something is wrong")
. It seems to me like the only bad design decision I've encountered so far in Rust -- that clearly reads as "I expect something is wrong". It seems that the intention was for it to be understood as "I expect this operation to succeed but, if not, then something is wrong", but it seems clear to me that the name doesn't work.
Thank you for the kind words :)
I thought so, too, but wanted to be on the safe side. So now the raw string is used to calculate the length, not one of the Style vectors derived from it. The config options are unchanged so far, however I agree that The right-align wrapping has been added. As such a line now does not start on the left I added an unstyled cell before it so it can be distinguished from wrapped whitespace. However this is not visible in the context/zero lines and a bit jarring in changed lines and I am open to suggestions.
Yes, it is weird, it took me a white to finally think of this as .expect_success_otherwise_panic_with("message") Also, more arrows, the first in the rows are ones currently used: ↵ ↲ ⮨ ⮰ ⤶ ⮐ ↩ / ↴ ⮷ ⮯ 🢱 ⤵ ⤸ ⬎ / (oh, some are blue here, in the terminal they are all monochrome as on the right) |
Hi @th1000s, I'm still very excited about the work here of course. Can you tell me where things stand and how I can help? By the way, using delta for its side-by-side mode was recently suggested in the GitHub blog here: https://github.blog/2021-03-11-scripting-with-github-cli/#make-ghyour-own so that's a nice additional context for your improvements to land in. |
I need to spend more time with the diff here but I've taken another look and it's looking fantastic to me. It's very impressive; there's a lot for me to learn from it, it improves on the previous implementation, and I know it involved grappling with a lot of details of the codebase! I think I can see a couple of bugs. You're probably aware of this one (the single space with no background colour before the
Also, I can crash delta on this branch by resizing my terminal to (e.g.) 80 characters and issuing
|
The space in front of the the right-aligned text was actually on purpose, a first draft to indicate where the line continues. I replaced it with And the other obvious improvement would be to not wrap lines by cutting up words so eagerly (see: |
Hi @th1000s,
Ah, OK great, I thought it was unlikely that you'd be unaware of it.
This is just a quick guess but this code comes to mind: Lines 536 to 572 in e7d1e28
|
@th1000s I've pushed a commit coalescing the two features into a single feature named
|
Any thoughts on the option names and defaults? On reflection |
Here are my suggestions, using the same prefix for all 3 right-align arguments:
|
I like your consistency improvements to the option names. One thought -- do you think perhaps the word "align" is superfluous? We could still have a shared prefix but keep it shorter as
|
Ok, I've done a review pass and I'll hand over to you now. Really exciting! I think delta might be about to possess humanity's most sophisticated side-by-side diff view! |
And more arg parsing issues: Adding support for signed integer / Or, instead of a magic -1 value for |
That would be fine with me, I'm certainly not attached to the magic -1. Maybe we can allow ∞ also. |
Validation moved to |
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've made two minor requests for changes -- I could do them but I don't want to make a mess of the history that you've been preserving.
Other than that, LGTM!! I'm not aware of anything else that needs addressing? Let me know if I've forgotten an outstanding issue that needs solving before merge but, otherwise, I'll merge this as soon as you tell me what you want to do with my two minor requests (i.e. you make them, or tell me to).
Panic when testing or exit with return value 2.
This does not use the values provided by default_value, so validation will fail.
If the current line does not fit into the panel, then it is not truncated but split into multiple lines. A wrapping symbol is placed at the end of the line. If the new line is short enough, it is right-aligned. Wrapping is limited to a certain number of lines (--wrap-max-lines), if this is exceeded the line is truncated by a now highlighted truncation symbol. To disable wrapping set this value to 0.
A few touch-ups, simplified Left/Right more, hit a nightly rustc crash, and it looks good to me as well! :) |
Thanks very much for this fantastic contribution @th1000s. It adds a feature that will significantly improve delta, and that many people have been looking forward to, it sets us up for additional wrapping-related improvements in the future, and it improves the codebase in many places, including via the addition of new patterns and techniques to the codebase that will be the source of still further codebase improvements in the future. Can you advise on which further changes you'd like to see merged before the next release? (#727?) |
Any idea when will it be released? This the feature that I've been waiting for. Delta is nice tool to compare many files in a scrollable screen. At least tell me how to build the cli tool. Cheers. |
Hi @fakhrulhilal, I agree, this is a very exciting addition to delta. We're pretty close to release I think. If you'd like to try out the unreleased master branch that would be great. The instructions to build are in the README; it's just the standard process for building a Rust executable. If you have any feedback on released or unreleased features, please do let us know. |
Just realize that it's in readme file already. I'll try in PC and I'll let you know when I have feedback. Thank you very much. |
This has now been released (delta v0.9.1). Thanks very much @th1000s for the huge amount of work put into this, improving the codebase in many ways as well as adding this eagerly-awaited feature. 🚀 |
+1 👍 |
If the current line does not fit into the panel, then
it is not truncated but split into multiple lines. A
wrapping symbol is placed at the end of the line.
Wrapping is limited to a certain number of lines, if this
is exceeded the line is truncated by a now highlighted
truncation symbol.
Commandline argument
-S
/--side-by-side-wrapped
.Also adapted
--keep-plus-minus-markers
logic, requiredto calculate the exact remaining panel width.
Updated* Example:
In the current state is is perfectly functional, however the limit of 5 wrapped lines is currently hard coded and I have not tested the behavior with
--tabs
yet. Also documentation beyond the stub in--help
has yet to be written, plus more tests.Ping #359 #299 #498
Let me know what you think!