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

🚀 Optional line wrapping #299

Open
augustobmoura opened this issue Aug 21, 2020 · 11 comments
Open

🚀 Optional line wrapping #299

augustobmoura opened this issue Aug 21, 2020 · 11 comments

Comments

@augustobmoura
Copy link

augustobmoura commented Aug 21, 2020

Sorry if this is repeated. I didn't find any similar issues.

Currently, when the line length exceeds its column, an arrow indicates that the line continues
image

I wish we could wrap the line like bat currently does and keep the diff highlighting.

Bat with line wrapping
image

@makew0rld
Copy link

I have a similar issue.

2020-08-23-183028_1920x1080_scrot

My lines are not wrapped at all when not in side-by-side mode, and so they go over where the line numbers would be. It'd be nice if the terminal size could be detected and then accounted for.

@mnsgs
Copy link

mnsgs commented Aug 26, 2020

I am seeing the same issue as referred by @augustobmoura - pretty much a standard Ubuntu 20.04 installation with the git/delta config:

[delta]
    line-numbers = true
    side-by-side = true
    plus-color = "#012800"
    minus-color = "#340001"
    syntax-theme = Monokai Extended

delta is of version 0.4.1.

@dandavison
Copy link
Owner

Hi all, thanks for this. I agree implementing line wrapping like bat does would be a nice feature. I don't think I'm going to be able to work on this in the near future so I'd welcome a pull request and am also happy to discuss what the code change might involve.

Some notes: There's a couple of related aspects to this:

  1. line wrapping respecting the line numbers panel in normal mode
  2. line wrapping in side-by-side mode, in the left panel and right panel

In normal mode we don't lose content today, it's just that it's not wrapped prettily in line-numbers mode. Personally I have the -S flag set in less, i.e. it's less -RS, so that content never wraps in normal mode (I personally find wrapped code very hard to read and prefer to scroll right when necessary).

However in side-by-side mode we currently lose content, because we can't allow the left panel to flow into the right panel's area and I did not attempt to implement line wrapping in the initial implementation of side-by-side because it would have been made the code change significantly more complicated than it already was.

It's maybe worth noting that in side-by-side mode, it is possible to have the panels use up more horizontal space than your terminal window has, by setting --width X (where X > your terminal width) and using the -S flag with less, and scroll right when needed.

Perhaps some of this could be helpful in the README.

@kevinhwang91
Copy link

sometimes I really want an option to truncate the long line. If with less -RS, the wrapping line symbol looks extremely ugly.
image

@dandavison
Copy link
Owner

@kevinhwang91 can you give a full example of a diff that you can't display in the way you want, and show the delta settings you're using? Note that we do have max-line-length now:

--max-line-length <max-line-length>
    Truncate lines longer than this. To prevent any truncation, set to zero. Note that syntax-highlighting very
    long lines (e.g. minified .js) will be very slow if they are not truncated [default: 512]

@kevinhwang91
Copy link

kevinhwang91 commented Oct 24, 2020

@kevinhwang91 can you give a full example of a diff that you can't display in the way you want, and show the delta settings you're using? Note that we do have max-line-length now:

--max-line-length <max-line-length>
    Truncate lines longer than this. To prevent any truncation, set to zero. Note that syntax-highlighting very
    long lines (e.g. minified .js) will be very slow if they are not truncated [default: 512]

It works, could delta adjust its value by the COLUMNS of the current terminal?
BTW, I found that it excludes the line number. I have no idea to zoom git diff to my column and truncate any chars long than my column.

@Kr1ss-XD
Copy link
Contributor

This doesn't seem to work in the git config files @kevinhwang91 - but I can achieve it with

git -c "core.pager=delta --max-line-length=$((COLUMNS - 10))" <git-subcommand>

Note that I needed to subtract 10 because the columns for the line numbers seem not to be included in the max-line-length that delta calculates. Depending on your configuration for line-number formatting, this might be a value smaller or greater than 10.

I agree it would be nice if delta could take the current terminal width into account. Besides $COLUMNS, it can also be queried by $(tput cols) if that helps.

@kevinhwang91
Copy link

kevinhwang91 commented Jan 25, 2021

git -c "core.pager=delta --max-line-length=$((COLUMNS - 10))" <git-subcommand>

Thanks, but I think I'm encountering an issue for delta, @dandavison , it seems that --max-line-length work as unexpected, here is the screenshot:
image

@CoelacanthusHex
Copy link

CoelacanthusHex commented Dec 19, 2021

I have tried auto line-wrapping algorithm implemented in #515, it works very well.
But I don't use side-by-side mode, many other users also don't use side-by-side mode.
And there are some modes that can't use side-by-side mode, such as git blame.
So we need the same auto line-wrapping algorithm as the one in side-by-side when we don't use side-by-side mode.
It maybe can reuse code, and core algorithm has been implemented.
Hope you can add it soon, we really require this feature to display our git diff and git blame better!
Thank you!

cc @th1000s, you have implemented line-wrapping in side-by-side mode, Could you please also take a look at the implementation of the line-wrapping algorithm in the non-side-by-side mode? Thanks very much!

@msrd0
Copy link

msrd0 commented Aug 28, 2022

Line wrapping by default for some languages like LaTeX would be extremely helpful. I find it quite annoying to do manual linebreaks for natural language paragraphs, where I want all lines to be of similar length (this is very different to source code of course). Line wrapping in text editors does exactly that. For now I'm using pager = delta --wrap-max-lines 16, but ultimately I'd like lines of any length to be wrapped with .tex files, but no line wrapping for ugly files like .min.js or .min.css.

@pahen
Copy link

pahen commented Feb 19, 2025

Thanks for delta! I really love it but I really miss this feature since I don't use side-by-side mode to make it fit better in VSCode. Have you thought more of this @dandavison @th1000s ?

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

No branches or pull requests

9 participants