Irregular scrolling in tmux

241 views
Skip to first unread message

Max Ng

unread,
Aug 24, 2020, 3:54:27 PM8/24/20
to chromium-hterm
I'm using the Secure Shell App on a Chromebook and I have this problem where scrolling feels very irregular when I'm using tmux. I can't describe the experience very well so I took a screen recording.

It looks to me this was caused by tmux and the terminal trying to scroll at the same time, so I tried toggling the "Emulate arrow keys with scroll wheel" option, but it didn't seem to help. Any idea how to fix this? I'm willing to debug a bit if someone can point me in the right direction.

Here is my .tmux.conf:

===

set -g default-terminal "tmux-256color"

# Panes start at 1 instead of 0, so that you can switch panes with one hand
set -g base-index 1
setw -g pane-base-index 1

# Allow customizing tab names using bash precmd_functions
set-option -g allow-rename on

# Move between split planes using vi-style keys
bind C-h select-pane -L
bind C-j select-pane -D
bind C-k select-pane -U
bind C-l select-pane -R

# Longer scrollback history
set -g history-limit 50000

# Scroll and copy using vi-style keys
set -g mode-keys vi
bind-key -T copy-mode-vi 'v' send-keys -X begin-selection
bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"

# Enable mouse and copy-and-paste, https://stackoverflow.com/a/46108732
set -g mouse on
bind-key -T copy-mode MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"

===

Thanks,
Max


Mike Frysinger

unread,
Aug 28, 2020, 1:42:39 AM8/28/20
to Max Ng, chromium-hterm
i'm not sure what i'm looking at here.  can you describe a bit what you're inputting during the screencast ?

is the [X/Y] tracker thing in the upper right coming from tmux ?  and it normally should be sticky in the upper right corner ?
-mike

--
You received this message because you are subscribed to the Google Groups "chromium-hterm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-hter...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-hterm/b3f15531-0a55-4887-8d49-f229a293edd7n%40chromium.org.

William Furr

unread,
Aug 28, 2020, 9:01:06 AM8/28/20
to Mike Frysinger, Max Ng, chromium-hterm
Yes, the yellow numbers are the tmux scroll position when in copy mode.  ctrl-b [

You can then scroll w/ mouse if you set that up, or with ctrl u/d.

It's definitely the terminal and tmux trying to scroll at the same time.  I don't know how other terminals solve this problem, maybe there's no scrollback from tmux in other terminals?  Or does tmux clear scrollback somehow?

Mike Frysinger

unread,
Aug 28, 2020, 1:38:29 PM8/28/20
to William Furr, Max Ng, chromium-hterm
thanks for the info.  does this only show up when using touchpad/mouse scrolling ?

i've seen flashing behavior with other apps (like `less`) where the status bar would jump around, but when i debugged them, hterm was representing the output correctly ... but other terminals didn't refresh as quickly/immediately, so the flashing wasn't as noticeable or jarring.  for example:
  yes | head -n10000 > f
  less ./f
  <scroll up/down and watch the status bar>

if it is related to scrolling in the browser, normally session managers use the alt screen which blocks scrollback entirely, or they set up a dedicated vt scroll region.  hterm should behave the same here, but will have to poke around.  i don't use tmux myself, but i can see if i can repro using your info.
-mike

William Furr

unread,
Aug 28, 2020, 1:56:45 PM8/28/20
to Mike Frysinger, Max Ng, chromium-hterm
I do see that flicker in the less output when scrolling with less, per your example.

I don't see any flicker in tmux when I scroll tmux with the built-in commands in copy mode.

I do see the flicker in tmux when scrolling using the touchpad.  It might be the same kind of flicker?  Just a lot more noticeable because the tmux position indicator is a solid yellow square with black numbers on it.

Max Ng

unread,
Aug 28, 2020, 2:12:39 PM8/28/20
to William Furr, Mike Frysinger, chromium-hterm
Thanks William for helping explain. Sorry I forgot to mention I was using the trackpad to scroll. I don't have a mouse right now so I wasn't able to test it.
It's not just the position indicator that's flickering --- the content flickers also. It's a bit hard to see with my test data because every line is of the same length, but it's quite noticeable when scrolling through real command line output.

ctrl+u/d does not have this problem. However if I scroll using the up or down arrow when the cursor is at the top or bottom of the screen, there is a little bit of flicker too: https://screencast.googleplex.com/cast/NTgxMTI0OTEzNDY5ODQ5NnxlNzNlZGI2OS0zYw
I don't know if these are caused by the same issue.

Ryan McCampbell

unread,
Dec 22, 2020, 7:29:28 PM12/22/20
to chromium-hterm, Max Ng, Mike Frysinger, chromium-hterm, William Furr
I can clearly notice this behavior using both tmux and less, and using either mouse or keyboard controls, although it is most jarring with mouse scrolling because that is more continuous. It seems that part of the top of the screen momentarily appears at the bottom whenever I scroll up. I don't notice any problem when scrolling down however. 

Max Ng

unread,
Dec 28, 2020, 7:20:29 PM12/28/20
to Ryan McCampbell, chromium-hterm, Mike Frysinger, William Furr
I fixed my problem! (mostly)
Turns out tmux defaults to scrolling 5 lines per mouse wheel escape sequence, which in combination with the number of mouse events generated by the browser makes things really erratic. Setting the scroll speed to 1 or 2 mostly solves the problem:

// replace copy-mode-vi with copy-mode if you are not using vi mode
bind-key -T copy-mode-vi WheelUpPane       send-keys -X -N 2 scroll-up
bind-key -T copy-mode-vi WheelDownPane     send-keys -X -N 2 scroll-down

The little yellow scroll position indicator still jumps up and down on the screen, but I can live with that. I tried hiding the scroll indicator, but after a few minutes I found it to be quite useful so I decided to keep it. If you prefer to hide it, you could modify the root WheelUpPane command and add the -H argument to copy-mode.

Some misc findings:
1. The reason "Emulate arrow keys with scroll wheel" didn't work was because the SSH app checks whether the terminal is in the primary screen. tmux uses the alternate screen. But I think this option is not what I'm looking for anyway.
2. The reason "Mouse scroll wheel multiplier" didn't do anything was because the scroll events are translated into escape sequences and sent to the terminal 1:1. There's no opportunity for the multiplier to kick in here.

Max Ng

unread,
Dec 28, 2020, 7:36:35 PM12/28/20
to Ryan McCampbell, chromium-hterm, Mike Frysinger, William Furr
Giving the position indicator a dimmer color also makes the jumping less jarring:

set -g mode-style bg=colour235,fg=colour245
Reply all
Reply to author
Forward
0 new messages