#!/bin/bash # Mon Jan 5 10:59:00 EST 2004 # NAME: mouse-demo # Copyright 2004, Chris F.A. Johnson # Released under the terms of the GNU General Public License about() #== Information about mouse-demo { cat < $charfile fi chars=$(< $charfile) } cls() #== clear screen { printf "${CLS:=`clear`}" } printat() #== print arguments 3-... at Y=$1 X=$2 { [ $# -lt 2 ] && return 1 local y=$1 local x=$2 shift 2 local msg="$*" printf "${CSI}%d;%dH%b" ${y//[!0-9]} ${x//[!0-9]} "$msg" } index() #== index return position of STR2 in STR1 { local idx case $1 in *$2*) idx=${1%%"${2}"*}; _INDEX=$(( ${#idx} + 1 )) ;; *) _INDEX=0 ;; esac } mouse_info() #== print mouse press information { local frmt="%16s %3d" clear_body xx=$(( $COLUMNS / 3 )) yy=3 ##$(( $LINES - 25 )) printat $((yy++)) $xx printf "$frmt" Button: $mouse_b printat $((yy++)) $xx printf "$frmt" Column: $mouse_x printat $((yy++)) $xx printf "$frmt" Row: $mouse_y printat $((yy++)) $xx printf "$frmt" "Mouse modifier:" $mouse_m printat $((yy++)) $xx "$cle" printf "Var. Length: B=%d X=%d Y=%d " ${#_MOUSE1} ${#_MOUSE2} ${#_MOUSE3} printat $((yy++)) $xx "$cle" printf "MOUSE1=%s MOUSE2=%s MOUSE3=%s " `ascii "$_MOUSE1$_MOUSE2$_MOUSE3"` } mouse_pos() #== convert character to mouse position { local MOUSE=$1 if [ "$MOUSE" = $'\x7f' ] then _MOUSE_POS=95 elif [ "$MOUSE" = "\\" ] then _MOUSE_POS=60 else index "$mouse_val_str" "$MOUSE" _MOUSE_POS=$_INDEX fi } read_mouse() #== decode mouse press information { IFS= read -r -d '' -sn1 -t1 _MOUSE1 || break 2 IFS= read -r -d '' -sn1 -t1 _MOUSE2 || break 2 IFS= read -r -d '' -sn1 -t1 _MOUSE3 || break 2 index "$mouse_val_str" "$_MOUSE1" mouse_b=$(( ($_INDEX & 3) + 1 )) mouse_m=$(( $_INDEX & (4 | 8 | 16) )) mouse_pos "$_MOUSE2" mouse_x=$_MOUSE_POS mouse_pos "$_MOUSE3" mouse_y=$_MOUSE_POS } get_key() #== store keypress from list of permissible characters { local OKchars=${1:-"$allkeys"} local k local error=0 local gk_tmo=${getkey_time:-${DFLT_TIME_OUT:-600}} local ESC_END=[a-zA-NP-Z~^$] mouse_x=0 mouse_y=0 mouse_b=0 mouse_line=0 printf "$mouse_on" stty -echo while :; do IFS= read -r -d '' -sn1 -t$gk_tmo _GET_KEY &1 || break index "$OKchars" "$_GET_KEY" if [ "$_INDEX" -gt 0 ] then case $_GET_KEY in ${ESC}) while :; do IFS= read -rst1 -d '' -n1 k