Skip to main content

Julia Evans

« back to all TILs

Two ways the mouse wheel works in the terminal

Learned today (thanks to Simon Tatham) that there are 2 different ways the mouse’s scroll wheel can work in the terminal:

  1. if the application (like less) enables the alternate screen buffer, then scroll events are ESC O A or ESC O B (like pressing the up and down keys)
  2. if mouse reporting is on, scroll events are reported to the program like other mouse events, as button press 4/5, with the coordinates of where your mouse was included

(as well as the default where your terminal emulator will just scroll the terminal window without telling the program that you’re scrolling)

This makes sense in retrospect because:

a) I’ve noticed that some TUI programs (like lazygit) have multiple areas and you can scroll each area independently with the mouse, which “feels’ like it would have to use mouse reporting” (and it does) a) it felt weird to me that less would support mouse reporting and indeed it doesn’t

I don’t think this is that useful in practice but it’s kind of interesting that sometimes the scroll wheel is just another way to press arrow keys really fast and sometimes it acts more like a GUI scroll wheel.