1

I recently had to setup a Windows computer. I usually remote into a linux box(Ubuntu) for development, so I'm using "Windows terminal" app with Window's built-in ssh client to login to my Linux box. Now I notice that I cannot use the trackpad/mouse to scroll through

  1. git logs
  2. man pages
  3. git diffs

I have to resort to arrow presses, which is not my preferred approach. I haven't been able to figure out who is responsible for paging in this workflow -

  • Windows terminal
  • Window's ssh client
  • My Linux box's pager settings (default pager is set to less there)

I have tried Alacritty on Windows with the same result, I have also tried WSL Ubuntu(within Windows terminal) to ssh login into the remote Linux box, but in vain.

Could someone help me understand how I could enable paging support/trackpad-mouse scrolling support in this setup?

rookie
  • 97
  • 1
  • 9

2 Answers2

6

It's both, in a way.

Although the terminal has its own "scrollback" (which you can access with mouse or scrollbar), full-screen programs – including pagers like 'less' – deliberately disable it while running (they enable the so-called alternate screen mode for full-screen operation), because they wouldn't have enough control over the terminal's scrollback. So instead the terminal-level scrolling is disabled in this mode, and all scrolling/paging is done custom by 'less'.

(In a sense, this is the whole point of using an in-terminal pager, instead of just dumping the whole text to terminal and scrolling it at terminal level. By doing scrolling internally, 'less' can start at the top of the file and let you scroll down, instead of always ending up at the bottom.)

Your main problem is that the 'less' pager simply doesn't have mouse support. (Terminal programs can request to directly receive mouse input1 – e.g. you will find native mouse scroll-wheel support in Vim or Elinks or WeeChat – but the 'less' pager does not do this.)

On a full Ubuntu environment, when you're somehow able to scroll with the wheel inside 'less', that's actually the terminal translating wheel events to fake Up/Down arrow keypresses – GNOME Terminal always does this when the alternate-screen mode is active, if the app hasn't activated direct mouse input.

(As a practical example, if you manually ask the terminal to switch to altscreen mode with tput smcup, and if you're using GNOME Terminal, then the mouse wheel will begin scrolling through your shell history. tput rmcup gets you back.)

So the secondary problem is that Windows Terminal doesn't provide wheel event emulation, either. It does support sending real wheel events to mouse-supporting programs (again, you can wheel-scroll in Vim while using Windows Terminal), but wheel-to-arrows is mostly unique to GNOME Terminal and other vte-based terminals.

Your options are:

  • Open a feature request at https://github.com/microsoft/terminal/ for the scroll emulation feature (if there isn't one already).
  • Use a pager with native mouse-event support (e.g. PAGER=elinks or vimpager to use Vim as a pager).
  • Use GNOME Terminal (or another vte-based terminal) through WSLg or X11 instead of Windows Terminal.
  • Don't use a pager at all, relying on the terminal's scrollback.

1 However, due to the way terminal APIs work in Windows, SSH is not 100% transparent (e.g. ssh.exe has to deliberately request "Unix-like terminal" mode rather than legacy "WinNT console" mode), and importantly here, older versions of OpenSSH for Windows (7.4p1, I think) were unable to relay any mouse events to the remote side. This has since been fixed – if you're at least on Windows 20H2 and have OpenSSH 8.1p1 or newer.

grawity
  • 501,077
1

It is pretty simple on Windows to convert mouse actions to scroll keys using the free AutoHotkey.

A simple AutoHotkey script for that is easy to write, but a more sophisticated and configurable AutoHotkey script is available at DragToScroll.

To run, after installing AutoHotKey, download the .zip of the DragToScroll repository and unzip to a folder, then run DragToScroll.ahk by a double-click on it. By default, the scroll is done by dragging the window using the right mouse/trackpad button.

You may stop the script by right-click on the green H icon in the traybar and choosing "Exit".

You may also right-click the H icon and choose "Settings" to configure the script. You may configure the scroll method, its speed, limit its actions to a single process (for example powershell.exe), and more.

To have it run on login, place it in the Startup group at
C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

harrymc
  • 498,455