htop etc and many others accept position dependent mouse clicks in
ssh shell. I know that
ssh is a command line interface. Then how does it accepts mouse clicks?
"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
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,
vim whatever. In this case
vim just sees the terminal sequence (like a simple series of keyboard events would produce), not the mouse event.