Bash – How some applications accept mouse click in bash over ssh

bashcommand linelinuxmousessh

Applications like lynx browser, htop etc and many others accept position dependent mouse clicks in bash over ssh shell. I know that ssh is a command line interface. Then how does it accepts mouse clicks?

Best Answer

IMHO, the simplest way to write such a TUI application is to use ncurses.

"New Curses" is a library that abstracts the design of the TUI from the details of the underlying device. All the software you cited use ncurses to render their interface.

When you click on a terminal emulator (e.g. xterm, gnome-term, etc), the terminal emulator translates the click in a sequence of ANSI Escape codes. These sequences are read and translated in events by the ncurses library.

You can find an example on Stack Overflow: Mouse movement events in NCurses

Related Question