#!/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 <<EOF
${B}mouse-demo${U}
A bash script that can be controlled entirely with the
mouse.
Requires: bash 2.0x or greater, ANSI/xterm window
Author: Chris F.A. Johnson
Date: 5 January 2004
Copyright 2004 Chris F.A. Johnson
This program may be copied under the terms of the
GNU General Public License, Version 2.
EOF
}
d2c () #== convert a decimal number to the corresponding ASCII character
{
x=`printf "%x" $1`
printf "%b" "\x$x"
}
set_chars() #== load string of all 255 chars from file (create if necessary)
{
charfile=$HOME/.chars
if ! [ -s $charfile ]
then
for c in `seq 1 255`; do
[ $c -eq 127 ] && c=9 ## 0x7f causes problems
d2c $c
done > $charfile
fi
chars=$(< $charfile)
}
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
}
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 </dev/tty 2>&1 || break
index "$OKchars" "$_GET_KEY"
if [ "$_INDEX" -gt 0 ]
then
case $_GET_KEY in
${ESC})
while :; do
IFS= read -rst1 -d '' -n1 k </dev/tty || break 2
_GET_KEY=$_GET_KEY$k
case $k in
$ESC_END)
[ "$_GET_KEY" = "$MSI" ] && { read_mouse; }
break 2
;;
esac
done
;;
*) break;;
esac
fi
done
printf "$mouse_off"
return $error
}
## commands to be placed in buttons
button_cmd=( cal df uptime who ps "ls -l" now help about exit )
## labels for button (customize if different from commands
buttons=( "${button_cmd[@]}" )
## keys for each button
button_keys=( c d u w p l n h a q )
## info to show with help command
help_strings=(
"Display amount of free and used memory in the system"
"Report filesystem disk space usage"
"Tell how long the system has been running"
"Show who is logged on"
"Report process status"
"Long listing of as many files as will fit on screen"
"Display date and time information"
"Help!"
"About this script"
"Exit"
)