6

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?

7

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

  • Great answer in a very interesting (at least for me) question! – k.Cyborg Jan 22 '18 at 18:34
3

It's pretty simple, in a old school serial terminal session, the mouse was not really an option for sending input to the interactive shell session. (I am sure there were some early exceptions.)

However when you are running a terminal emulator inside a graphical desktop session the terminal emulator can be mouse aware.

What happens on a high level is that the mouse events are translated by the terminal emulator (xterm for example) into terminal sequences and those are sent to the interactive shell session the application you are running, htop, vim whatever. In this case vim just sees the terminal sequence (like a simple series of keyboard events would produce), not the mouse event.

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.