zsh-users
 help / color / mirror / code / Atom feed
* [tip] mouse support
@ 2004-11-11 12:20 Stephane Chazelas
  2004-11-11 14:40 ` Peter Stephenson
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Stephane Chazelas @ 2004-11-11 12:20 UTC (permalink / raw)
  To: Zsh users list

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2004-11-15 13:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-11 12:20 [tip] mouse support Stephane Chazelas
2004-11-11 14:40 ` Peter Stephenson
2004-11-11 16:22   ` Stephane Chazelas
2004-11-11 17:47     ` Bart Schaefer
2004-11-11 18:05       ` Stephane Chazelas
2004-11-11 18:22       ` Stephane Chazelas
2004-11-12  1:02         ` Bart Schaefer
2004-11-12  9:22           ` Stephane Chazelas
2004-11-11 16:07 ` Andy Spiegl
2004-11-11 17:26   ` Stephane Chazelas
2004-11-12 12:02 ` [tip] mouse and mouse-wheel support! Stephane Chazelas
2004-11-15 12:21   ` Stephane Chazelas
2004-11-15 13:14     ` Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).