1

When using a program like htop - mouse scroll wheel action will not do anything.

How can I reproduce such behavior in my Bash script?

I guess there should be a way to tell the terminal to ignore scrolling requests. How is that done?

2

htop happens to use ncurses

ncurses (and other things that use the full screen in a terminal) initializes the terminal using the terminfo capability smcup. For xterm (and terminal emulators that imitate it), that switches to the alternate screen. Those terminals may respond to a wheel mouse by sending up/down cursor keys instead of scrolling the terminal window (which you would see in htop by the focus-line moving up/down). Your bash script may see those cursor keys, but not handle them.

You can experiment with the feature in a script using

tput smcup

to switch to the alternate screen, and

tput rmcup

to switch back to the normal screen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.