You can inject input events with xdotool. You can invoke commands on a key press with xbindkeys. Put something like this in your ~/.xbindkeysrc
:
"xdotool click 4"
control+shift+prior
"xdotool click 5"
control+shift+next
bash
has the built-in ability to call an external editor to edit the current command line you're working on. Mouse support depends on the editor used.
If you're using bash
's emacs-like mode, use Ctrl-XCtrl-E to access the editor.
If you're using vi-like keybindings, use ESCv
You can also use the built-in fc
command to edit any previous line.
$ help fc
fc: fc [-e ename] [-lnr] [first] [last]
or fc -s [pat=rep] [command]
Display or execute commands from the history list.
fc
is used to list or edit and re-execute commands from the history list. FIRST and LAST can be numbers specifying the range, or FIRST can be a string, which means the most recent command beginning with that string.
Options:
-e ENAME
select which editor to use. Default is $FCEDIT
, then $EDITOR
, then vi
[...]
BTW, one small annoyance with this (in any of its forms):
There may be some simple way to abort an edit or to make bash return to editing the line itself and NOT execute it immediately, but I've never found one (I haven't looked very hard).
Quit-without-saving just executes the line as it was before you called the editor.
The only way I've found is to delete the entire buffer in the editor, then save and exit. Or add a #
comment at the beginning, of course.
PS: I use emacs-mode line editing and Ctrl-XCtrl-E for vim
when i need real editing power. I don't know why, I love vi
and vim
, but I just don't like vi-mode on the command line.
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