From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19294 invoked from network); 11 Nov 2004 12:20:50 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 11 Nov 2004 12:20:50 -0000 Received: (qmail 22852 invoked from network); 11 Nov 2004 12:20:43 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Nov 2004 12:20:43 -0000 Received: (qmail 7590 invoked by alias); 11 Nov 2004 12:20:33 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8195 Received: (qmail 7580 invoked from network); 11 Nov 2004 12:20:32 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 11 Nov 2004 12:20:32 -0000 Received: (qmail 21842 invoked from network); 11 Nov 2004 12:20:32 -0000 Received: from smtp-out6.blueyonder.co.uk (195.188.213.9) by a.mx.sunsite.dk with SMTP; 11 Nov 2004 12:20:31 -0000 Received: from sc ([82.41.214.33]) by smtp-out6.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.6713); Thu, 11 Nov 2004 12:20:58 +0000 Date: Thu, 11 Nov 2004 12:20:11 +0000 From: Stephane Chazelas To: Zsh users list Subject: [tip] mouse support Message-ID: <20041111122011.GB4451@sc> Mail-Followup-To: Zsh users list Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.6i X-OriginalArrivalTime: 11 Nov 2004 12:20:58.0481 (UTC) FILETIME=[E6631610:01C4C7E8] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: * X-Spam-Status: No, hits=1.5 required=6.0 tests=RCVD_IN_SORBS autolearn=no version=2.63 X-Spam-Hits: 1.5 Hi zsh users, I just posted that to comp.unix.shell, I thought it might be of some interest for some of you. Basically, it's cursor positionning with the mouse under xterm like terminals (works with xterm, gnome-terminal and rxvt AFAICS, probably also with putty, not if there are tabs or NLs (or multi-byte characters) in the zle buffer). I'm not used to writing zle code. Please tell me what you think. ### code begins if [[ $TERM = *xterm* ]]; then zle-xterm-mouse() { emulate -L zsh setopt extendedglob # for (#b) local bt mx my cx cy i match mbegin mend read -k bt # mouse button, x, y reported after \e[M read -k mx read -k my [[ $bt = "#" ]] || return 0 # only for btn1 release print -n '\e[6n' # query cursor position while read -k i && [[ $i != R ]]; do cx+=$i; done # can't use read -d R in zle [[ $cx = (#b)??(*)\;(*) ]] || return cy=$match[1] cx=$match[2] (( CURSOR += #mx - 32 - cx + (#my - 32 - cy) * COLUMNS )) return 0 } precmd() { # enable mouse tracking print -n '\e[?1000h' } preexec() { # disable mouse tracking print -n '\e[?1000l' } zle -N zle-xterm-mouse zle-xterm-mouse bindkey '\e[M' zle-xterm-mouse fi ### code ends -- Stéphane