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

Support mouse scroll #58

Closed
Nashenas88 opened this issue Nov 20, 2019 · 28 comments
Closed

Support mouse scroll #58

Nashenas88 opened this issue Nov 20, 2019 · 28 comments

Comments

@Nashenas88
Copy link

In the default git pager (less on my system) I can use the mouse scroll wheel to scroll through the pager output. When delta is used, the mouse scroll does not work, and I'm forced to use the navigation shortcuts. It would be really nice to be able to scroll with the mouse wheel.

System: Linux pop-os 5.3.0-22-generic #24+system76~1573659475~19.10~26b2022-Ubuntu SMP Wed Nov 13 20:0 x86_64 x86_64 x86_64 GNU/Linux

@Darkhogg
Copy link

Darkhogg commented Dec 3, 2019

Please. This is the one thing preventing me from using delta.

@dandavison
Copy link
Owner

Hi, thanks for the report, let's get to the bottom of this. You might have to help me out a bit as I don't usually use a mouse. Are you familiar with bat? The code in delta relating to paging is literally copied from bat, and my intention in doing that was that the two projects would behave the same in these respects. So, there are many issues in the bat github repo concerning scrolling. Ultimately, the solution the bat author recommends is described here: https://github.com/sharkdp/bat#using-a-different-pager.

Would you be able to do the following?

  1. Try out bat and see if you find the same problems with scrolling there as with delta.
  2. Tell me if the solution recommended by bat works for you in delta.

Maybe you could help me understand something: I've read the various bat issues but I don't think I understand what people mean when they talk about "scrolling in less". I have just located a mouse and I find (in MacOS iTerm2 and Terminal.app) that the scroll wheel scrolls the terminal application's main scroll bar, and so "scrolling works" in a sense for delta, less and bat.

@Darkhogg
Copy link

Darkhogg commented Dec 3, 2019

Tried to use bat, same problem as with delta.
Tried to set export BAT_PAGER="less -irRSx4", where the less options were copied from my $LESS env var, worked like a charm.

Try to run less -irRSx4 with a big file to see what we mean by scrolling, BTW.

@dandavison
Copy link
Owner

dandavison commented Dec 4, 2019

worked like a charm.

OK, just to be totally clear, did it work like a charm in both delta and bat? (It should.) So maybe we can close this issue by updating the README to explain that the solution is the same as bat?

@ronjouch
Copy link
Contributor

ronjouch commented Dec 4, 2019

Did export BAT_PAGER="less -irRSx4" work like a charm in both delta and bat? (It should.) So maybe we can close this issue by updating the README to explain that the solution is the same as bat?

@dandavison @Darkhogg thanks! I confirm that export BAT_PAGER="less -rR" fixes mouse wheel scrolling in both delta (e.g. showing a big diff) and raw bat (e.g. ls /usr/bin | bat). Notes:

  • Options i, S and x4 mentioned by @Darkhogg are unrelated.
  • less' manpage suggests there is a nuance between r and R, but I couldn't be bothered to understand it. Both work fix mouse wheel scrolling, and bat's README suggests to use -R
  • Actually, bat's README suggests to use -RFX and maybe -S but, for me (Ubuntu 19.10), F causes null output, X breaks mouse scroll, and S doesn't fix it (😄). So for me export BAT_PAGER="less -iRx4" it is.

@dandavison a mention in the README seems appropriate to me too. Thanks for delta!!!

@Darkhogg
Copy link

Darkhogg commented Dec 4, 2019

Oh, nice, I didn't realize that was supposed to make delta work, I just tried bat.
To confirm: It works in delta too, just checked.
The fact that I have to use a bat env var for this is a bit confusing but I'll take it.

@dandavison
Copy link
Owner

dandavison commented Dec 4, 2019

@Darkhogg @ronjouch awesome, I'll add the explanation to the README.

@Darkhogg You actually don't have to use a bat env var; delta also honors the standard Unix PAGER env var (giving precedence to BAT_PAGER). And bat also honors both of them with the same precedence rule. My thinking was that adding a DELTA_PAGER to this would have been unnecessarily confusing :)

In general, my intention is for delta in some ways to be a companion tool to bat. bat does not implement language-specific syntax highlighting for diff output, or for the multi-language diff output produced by git diff (see sharkdp/bat#23), since it's a different problem from the syntax-highlighting-a-single-language-file problem that bat solves. But both bat and delta are written in Rust and, since they both use syntect, they use the same format for color themes and language syntax descriptions. So, my intention is basically that a bat user's bat configuration will, where appropriate, be honored automatically by delta. So far, that is true for BAT_PAGER, and I plan (#19) to make delta read custom themes and syntax definitions from the same location as bat (~/.cache/bat), so that the same process can be used for adding new themes/languages: https://github.com/sharkdp/bat#adding-new-syntaxes--language-definitions. I'd be happy to hear any thoughts on whether this makes sense.

@ronjouch
Copy link
Contributor

ronjouch commented Dec 4, 2019

@Darkhogg You actually don't have to use a bat env var; delta also honors the standard Unix PAGER env var (giving precedence to BAT_PAGER). And bat also honors both of them with the same precedence rule.

Hmmm yes, and bat is supposed to user PAGER too, see bat's README / Using a different pager. However, setting PAGER to less -iRx4 didn't fix scrolling in bat, I did have to set BAT_PAGER to fix it. So, staying with BAT_PAGER. Not sure what's going on, maybe bat's handling of PAGER is confused by arguments?

@dandavison
Copy link
Owner

@ronjouch is that the effect of the precedence rule? Is PAGER honored if you do unset BAT_PAGER first (assuming you're using bash).

As an extra level of complexity, I believe that for bat, setting the env vars to empty string (e.g. export BAT_PAGER=) will not cause them to be ignored: they have to be literally not set / unset. But for delta, I have made delta ignore the env vars if they are empty. I hadn't thought it through sufficiently to decide whether I should open an issue against bat or not.

@ronjouch
Copy link
Contributor

ronjouch commented Dec 4, 2019

@dandavison I'm using the fish shell, and I tested my change in a fresh session after editing my config.fish :

  • With BAT_PAGER set to less -iRx4 (and PAGER unset), mouse scrolling works in ls -la /usr/bin
  • With PAGER set to less -iRx4 (and BAT_PAGER unset), mouse scrolling doesn't work in ls -la /usr/bin

@Nashenas88
Copy link
Author

For me, setting BAT_PAGER='less -R' works. PAGER isn't respected for me.

@dandavison
Copy link
Owner

Ah sorry, that's right, bat (and therefore delta, which uses a bat's code here) replaces the arguments to less when PAGER is the only env var set. OK, it's all a bit confusing, and there's the --pager argument which bat has and delta does not currently. So plenty of degrees of freedom...

I'm glad we have a solution here and I'll ping this ticket again when I add an explanation to the README. (Unless someone else wants to which would also be great).

dandavison added a commit that referenced this issue Dec 4, 2019
README: Document env. var to fix mouse scrolling (fix #58)
@dandavison
Copy link
Owner

I think this issue can stay closed now. Thanks all and thanks @ronjouch who added a section on mouse scrolling to the README.

@danielsanfr
Copy link

Hello people. First, what an incredible tool this is!

I know this is probably not a problem in delta, but if anyone can help me, I will be very grateful.

I'm using fish as my main shell, and my problem follows below:

If I set the EV using set -Ux BAT_PAGER "less -RF", then call zsh, the diff will be the way I want it.
So if inside the zsh I call the fish, the diff is also the way I want it.
However if I call the exit from fish to zsh and call the exit again to go back to the initial (or main) fish, the diff does not work the way I want.

I tried to set the environment variable through the ~/.config/fish/config.fish file but I also got the same behavior reported above.

I decided to ask here, because maybe if I had the --pager option, I could solve this problem as delta --pager="less -RF".

@brkn
Copy link

brkn commented Aug 26, 2020

My less version was less 487 on MacOS mojave.

less --version
less 487 (POSIX regular expressions)

I just installed less from brew and linked it. Now scrolling just works. Didn't change any configs etc.

brew install less
brew link less
less --version
less 551 (PCRE regular expressions)
Copyright (C) 1984-2019  Mark Nudelman

@freak4pc
Copy link

freak4pc commented Oct 5, 2020

Wonderful wonderful tool. I can't get scrolling to work on zsh. Tried less -iRx4 and less -R for BAT_PAGER. Happy to try anything else if you have thought :) Thanks all.

@Kr1ss-XD
Copy link
Contributor

Kr1ss-XD commented Oct 5, 2020

@freak4pc You could try to append --mouse or --MOUSE to the LESS (or BAT_PAGER) environment variable, depending on the direction you to use your mouse wheel in. 😉

Your terminal emulator needs to support mouse events for this to work, of course.

The number of lines to scroll with the wheel can be adjusted with --wheel-lines=<n>.

@OliverJAsh
Copy link

Mac user here. I tried the steps outlined in the docs (install latest less and/or BAT_PAGER='less -R') to no avail.

However, I did manage to get it working with BAT_PAGER='less -+X'.

This is the same fix as suggested in this issue for diff-so-fancy: so-fancy/diff-so-fancy#246.

@camsteffen
Copy link

Another Mac user. Just updating less with brew install less worked for me.

@gabriel-del
Copy link

It worked to me with:

export DELTA_PAGER="less --mouse"

On ~/.bashrc

@calestyo
Copy link

Hey there.

When I use e.g. DELTA_PAGER='less --mouse', then scrolling in delta works for me, however it doesn't without, which is strange, as both my bat and less do support mouse scrolling out of the box.

188565 pts/8    S+     0:00 git diff HEAD~10
 188566 pts/8    Sl+    0:00 /usr/bin/delta
 188570 pts/8    S+     0:00 less --RAW-CONTROL-CHARS --quit-if-one-screen

Apparently my delta uses less per default and adds --RAW-CONTROL-CHARS --quit-if-one-screen, but even with these options a standalone less on some file has working mouse scrolling support.

There are no aliases or so, that would cause that.

Cheers,
Chris.

@dandavison
Copy link
Owner

dandavison commented Oct 10, 2023

Hi @calestyo, hm, definitely the same version of less being used? Have you checked what ps says for the other scenarios? Is it possible you have something in LESS? There's some good discussion in this thread: #630

@calestyo
Copy link

Hey @dandavison

With my standalone less and aliases cleared I got:

 223440 pts/10   S+     0:00 less

so no parameters, and:

$ cat /proc/223440/environ  | tr '\0' '\n' | grep -Ei 'pager|less|delta'
LESSCLOSE=/usr/bin/lesspipe %s %s
LESSOPEN=| /usr/bin/lesspipe %s
_=/usr/bin/less

But these shouldn't affect scrolling (which works).

At the same time for delta via git:

 225803 pts/13   S+     0:00 git diff HEAD~10
 225804 pts/13   Sl+    0:00 /usr/bin/delta
 225808 pts/13   S+     0:00 less --RAW-CONTROL-CHARS --quit-if-one-screen

with:

$ cat /proc/225808/environ  | tr '\0' '\n' | grep -Ei 'pager|less|delta'
LESS=FRX
LESSANSIENDCHARS=mK
LESSCHARSET=UTF-8
LESSCLOSE=/usr/bin/lesspipe %s %s
LESSHISTFILE=/home/calestyo/.local/share/delta/lesshst
LESSOPEN=| /usr/bin/lesspipe %s

(with scrolling not working)

Now delta alone:

$ git format-patch HEAD~10 --stdout > foo.patch
$ cat foo.patch | delta 

gives:

 228058 pts/7    Sl+    0:00 delta
 228062 pts/7    S+     0:00 less --RAW-CONTROL-CHARS --quit-if-one-screen

with:

$ cat /proc/228062/environ  | tr '\0' '\n' | grep -Ei 'pager|less|delta'
LESSANSIENDCHARS=mK
LESSCHARSET=UTF-8
LESSCLOSE=/usr/bin/lesspipe %s %s
LESSHISTFILE=/home/calestyo/.local/share/delta/lesshst
LESSOPEN=| /usr/bin/lesspipe %s
_=/usr/bin/delta

(with scrolling working).

Now I played around and set LESS manually to combinations of FRX and ran cat foo.patch | delta.

It's the X in LESS that breaks scrolling.

Next I wanted to see whether git is the "offender" ;-) who sets the X, and from my git_config where I have these with respect to delta:

[core]
        pager = delta
…
[interactive]
       diffFilter = delta --color-only
…
[delta]
        navigate = true

I accidentally commented only:

[interactive]
       diffFilter = delta --color-only

(which I merely have because of delta’s README.md)

But that's already it, with that, I get:

 231643 pts/7    S+     0:00 git diff HEAD~10
 231644 pts/7    Sl+    0:00 /usr/bin/delta
 231648 pts/7    S+     0:00 less --RAW-CONTROL-CHARS --quit-if-one-screen

and:

$ cat /proc/231648/environ  | tr '\0' '\n' | grep -Ei 'pager|less|delta'
LESS=FR
LESSANSIENDCHARS=mK
LESSCHARSET=UTF-8
LESSCLOSE=/usr/bin/lesspipe %s %s
LESSHISTFILE=/home/calestyo/.local/share/delta/lesshst
LESSOPEN=| /usr/bin/lesspipe %s

So I'd guess it's in fact delta, which adds the X when --color-only is used?!

Is it really needed (I guess so)?

And if, couldn’t you just also add --mouse?

That would make behave more like people expect from less.

At least my less scrolls per default, even without --mouse). I looked into that, and it seems to be a VTE speciality (presumably it sends UP and DOWN?).

Trying it in xterm and my less no longer scrolls per default (unless --mouse is given).

So probably, you should actually not not add --mouse, unless perhaps you detected that VTE is used (e.g. via the VTE_VERSION env var).

But problem with that would still be, that there'd be no longer a direct way for people do specifically disable mouse scrolling (there is no --no-mouse option, so you'd need to add some option to delta to disable that quirk).

Yeah not really sure what would be the best way to go.

Cheers,
Chris.

@dandavison
Copy link
Owner

dandavison commented Oct 11, 2023

Hm, neither delta, nor the bat crate that delta uses in places, alter the LESS env var, AFAIK. (But we do add arguments to the child process invocation when the user has not configured less themselves)

Also my understanding is that the [interactive] stanza in gitconfig is only in effect during operations such as git add -p or --interactive.

Could you double check the part of your experiment where you found that

[interactive]
       diffFilter = delta --color-only

adds X to the LESS env var under a git diff invocation? I don't think that should be the case.

@calestyo
Copy link

calestyo commented Oct 11, 2023

Uhm... I have no idea how I've managed to mess that up ^^ (=sorry)

Trying it again, I couldn't reproduce it.

So dug further and found:
https://github.com/git/git/blob/aab89be2eb6ca51eefeb8c8066f673f447058856/Documentation/config/core.txt#L550-L562

So git is the "offender" ;-) ... an in fact, even the delta process has the env var already set to FRX.

I've asked at the git mailing list, why they even add X, presumably to avoid clearing the screen after exiting.

Next I'd ask less upstream, why X causes VTE’s scrolling to break, and whether there's some out-of-the-box solution.

@dandavison
Copy link
Owner

Ok great, that's progress!

@RReverser
Copy link

Hm is there any cross-platform solution that would work on Windows? (like native Rust tools do) less is not really an option here unless I install from GNU utils or something.

@injust
Copy link
Contributor

injust commented Jul 1, 2024

After reading a lot of threads, passing --redraw-on-quit to less instead of -X was the minimal and best solution I found. You can do this by changing core.pager from delta to LESS='FR --redraw-on-quit' delta.

git sets LESS=FRX by default. One workaround is to add --mouse, but this results in unnatural scrolling (explanation in gwsw/less#445 (comment)). You can "fix" it with --wheel-lines=N, but because --mouse scrolling is handled by less, you lose native scrolling features like inertia (very noticeable on a touchpad).

Another workaround is to omit -X (set core.pager to LESS=FR delta). You get native scrolling, but the pager content disappears after you exit less, which does not match the default non-delta behavior.

IMO the best solution is to replace -X with --redraw-on-quit. This maintains native scrolling and preserves the pager content after you exit less. You do need a new-enough version of less that has this option, though.


Sorry for necroing, but I figured this was useful information to have here (especially as https://dandavison.github.io/delta/tips-and-tricks/mouse-scrolling.html points to this issue).

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