Giter Site home page Giter Site logo

Support mouse scroll about delta HOT 27 CLOSED

dandavison avatar dandavison commented on May 6, 2024 10
Support mouse scroll

from delta.

Comments (27)

Kr1ss-XD avatar Kr1ss-XD commented on May 6, 2024 10

@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>.

from delta.

OliverJAsh avatar OliverJAsh commented on May 6, 2024 5

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.

from delta.

brkn avatar brkn commented on May 6, 2024 4

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

from delta.

ronjouch avatar ronjouch commented on May 6, 2024 3

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!!!

from delta.

camsteffen avatar camsteffen commented on May 6, 2024 3

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

from delta.

dandavison avatar dandavison commented on May 6, 2024 2

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

from delta.

freak4pc avatar freak4pc commented on May 6, 2024 1

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.

from delta.

gabriel-del avatar gabriel-del commented on May 6, 2024 1

It worked to me with:

export DELTA_PAGER="less --mouse"

On ~/.bashrc

from delta.

Darkhogg avatar Darkhogg commented on May 6, 2024

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

from delta.

dandavison avatar dandavison commented on May 6, 2024

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.

from delta.

Darkhogg avatar Darkhogg commented on May 6, 2024

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.

from delta.

dandavison avatar dandavison commented on May 6, 2024

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?

from delta.

Darkhogg avatar Darkhogg commented on May 6, 2024

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.

from delta.

dandavison avatar dandavison commented on May 6, 2024

@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.

from delta.

ronjouch avatar ronjouch commented on May 6, 2024

@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?

from delta.

dandavison avatar dandavison commented on May 6, 2024

@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.

from delta.

ronjouch avatar ronjouch commented on May 6, 2024

@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

from delta.

Nashenas88 avatar Nashenas88 commented on May 6, 2024

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

from delta.

dandavison avatar dandavison commented on May 6, 2024

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).

from delta.

danielsanfr avatar danielsanfr commented on May 6, 2024

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".

from delta.

calestyo avatar calestyo commented on May 6, 2024

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.

from delta.

dandavison avatar dandavison commented on May 6, 2024

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

from delta.

calestyo avatar calestyo commented on May 6, 2024

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.

from delta.

dandavison avatar dandavison commented on May 6, 2024

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.

from delta.

calestyo avatar calestyo commented on May 6, 2024

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.

from delta.

dandavison avatar dandavison commented on May 6, 2024

Ok great, that's progress!

from delta.

RReverser avatar RReverser commented on May 6, 2024

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.

from delta.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.