jjui icon indicating copy to clipboard operation
jjui copied to clipboard

Custom pager: `delta` with `side-by-side` diff window incorectly sized

Open IzawGithub opened this issue 3 months ago • 6 comments

Description

Using jjui with the delta pager with delta side-by-side option enabled makes the diff window of jjui incorrectly sized.

Steps to Reproduce the Problem

  1. Install delta (0.18.2)
  2. Configure it with: ~/.gitconfig
[delta]
    side-by-side = true

# Add this if you want to check the expected output from a `git diff`
[core]
    pager = delta

OR

export DELTA_FEATURES=+side-by-side
  1. Launch a repo with jjui
  2. Open a diff view with d, or check a preview with p

Expected Behavior

What delta should look like:

Normal delta

Actual Behavior

How delta actually looks like:

jjui delta

Specifications

  • Platform: Tested on two machine:
    • Ubuntu 25.04 6.14.0-29-generic x86_64
    • Arch 6.18.8-zen2-1-zen x86_64
  • Version: 0.9.3

IzawGithub avatar Sep 24 '25 10:09 IzawGithub

Hey, thanks.

I think this was discussed in #54 but without a proper solution. I don't know exactly why this is happening but my guess is that delta is not getting the terminal size information because it is started within jjui and defaulting to a size of 50 or something like that.

Unfortunately, I don't currently have the bandwidth to investigate this, but I will get back to this at some point.

idursun avatar Sep 26 '25 07:09 idursun

I also ran into this. Here's how I fixed it:

Since recently, jj passes a $width parameter to external diff tools: https://github.com/jj-vcs/jj/pull/7502. It hasn't been released yet, so I did: cargo install --git https://github.com/jj-vcs/jj jj-cli

~/.config/jj/config.toml:

[ui]
diff-formatter = ["delta", "--width", "$width", "$left", "$right"]

krksgbr avatar Sep 30 '25 09:09 krksgbr

Since recently, jj passes a $width parameter to external diff tools

Shortly after your comment, jj ships this feature into the release of 0.34.0, and I gladly took the change to try your solution.

The most part of it works fine, but there's always an annoying warning whenever I call jj diff:

Warning: Tool exited with exit status: 1 (run with --debug to see the exact invocation)

which won't produce any further warnings with --debug.

On the jjui side, the default diff works fantastic and I can finally enjoy some pretty diff. However the only issue is that in the preview panel, the width passed to delta seems to be the whole page width, instead of the panel width, which makes the preview only displaying half the content:

Image

Which I think can be fixed in jjui, maybe?

TeddyHuang-00 avatar Oct 03 '25 17:10 TeddyHuang-00

The most part of it works fine, but there's always an annoying warning whenever I call jj diff:

Warning: Tool exited with exit status: 1 (run with --debug to see the exact invocation)

which won't produce any further warnings with --debug.

@TeddyHuang-00

delta is expected to exit with 1 when there's an actual diff. paginating the output will hide the warning (should be the default setting in jj I think), but if you prefer to not paginate, you can do this to suppress the warning:

diff-formatter = ["bash", "-c", "delta --width $width $left $right || true"]

However the only issue is that in the preview panel, the width passed to delta seems to be the whole page width, instead of the panel width, which makes the preview only displaying half the content:

the non-side-by-side layout works much better in jjui previews. long lines will still be cut off, but it's much better. relevant config:

~/.config/git/config*

[delta "split-view"]
    side-by-side = true

[delta "non-split-view"]
    side-by-side = false

[delta]
    features = split-view
    navigate = true
    line-numbers = true

~/.config/jj/config.toml

[merge-tools.delta-non-split-view]
program = "delta"
diff-args = ["--width", "$width", "--features", "non-split-view", "$left", "$right"]

~/.config/jjui/config.toml

[preview]
revision_command = ["show", "--color", "always", "-r", "$change_id", "--config", "ui.diff-formatter=delta-non-split-view"]

krksgbr avatar Oct 03 '25 22:10 krksgbr

delta is expected to exit with 1 when there's an actual diff. paginating the output will hide the warning (should be the default setting in jj I think), but if you prefer to not paginate, you can do this to suppress the warning:

diff-formatter = ["bash", "-c", "delta --width $width $left $right || true"]

Well, I have everything else as default, and the error is visible regardless of being paginated or not (although the error will appear as content at the bottom of pager). The workaround works, though.

And your solution to the side-by-side view works like a charm. It is much usable now. Thank you so much!

P.S. Besides the revision_command, the file_command should also be set similarly with config option.

TeddyHuang-00 avatar Oct 03 '25 22:10 TeddyHuang-00

@TeddyHuang-00 thanks for sharing the config!

this is honestly so good, make jjui even more enjoyable to use. having a non-side-by-side diff at preview and a side-by-side one at diff view is so nice

this should be widely shared!

baggiiiie avatar Oct 24 '25 19:10 baggiiiie