Giter VIP home page Giter VIP logo

mouse_xterm's Introduction

Mouse support on readline

The following code enables clicks to move cursor in bash/readline on xterm

  1. Enable xterm mouse tracking reporting
  2. Set readline bindings to consume the escape sequence generated by clicks

Quickstart

mkdir Mouse && cd Mouse
git clone --depth=1 https://github.com/tinmarino/mouse_xterm .
source mouse.sh && mouse_track_start
# Press C-l after using mousewhell because it has to disable mouse tracking to work

Xterm

Xterm have a mouse tracking feature

echo -e "\e[?1000;1006;1015h" # Enable tracking
echo -e "\e[?1000;1006;1015l" # Disable tracking
  • Mouse click looks like \e[<0;3;21M and a release \e[<0;3;21. Where 2 is x (from left) and 22 is y (from top)
  • Mouse whell up : \e[<64;3;21M
  • Mouse whell down : \e[<65;3;21M
  • Press C-v after enabling the mouse tracking to see that

Bash

Readline can trigger a bash callback

bind -x '"\e[<64;": mouse_void_cb' # Cannot be put in .inputrc
bind    '"\C-h"   : "$(date) \e\C-e\ef\ef\ef\ef\ef"' #Can be put in .inputrc

Readline can call multiple functions

# Mouse cursor to begining-of-line before calling click callback
bind    '"\C-98" : beginning-of-line'
bind -x '"\C-99" : mouse_0_cb'
bind    '"\e[<0;": "\C-98\C-99"'

Readline callback can change cursor (point) position with READLINE_POINT environment variable

bind -x '"\C-h"  : xterm_test'
function xterm_test {
	echo "line is $READLINE_LINE and point $READLINE_POINT"
	READLINE_POINT=24    # The cursor position (0 for begining of command)
	READLINE_LINE='coco' # The command line current content
}

Perl (reply)

TODO no comment yet, I could not invoke a readline command or I would have lost $term->{point}

Python (ipython)

Ipython supports mouse. See Ipython/terminal/shortcuts -> Prompt-toolkit/bingin.mouse

ipython --TerminalInteractiveShell.mouse_support=True

Or to enable at startup write in .ipython/profile_default/ipython_config.py

c = get_config()
c.TerminalInteractiveShell.mouse_support

Limitations

  • OK : bash, ipython3, tmux
  • NO : python, reply
  • DISABLED : vim

Links

mouse_xterm's People

Contributors

i026e avatar tinmarino avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.