#!/bin/ksh # # @(#)dtcommand 1.3 96/11/19 11:01:16 # # William S. Annis wrote this. He doesn't # care who uses it or sends it to their friends, but he'd strongly # prefer people leave his name attached to it. # # dtcommand - echo out the escape sequences for a dtterm. # # Commands available: # # title "Some title" # iconify # deiconify # move x y # resize h w # front # back # refresh | redraw # bg | background COLOR # fg | foreground COLOR # Where color is one of black, red, green, yellow, blue, magenta, cyan # white or default. # Helper functions function color_low { # This returns 0-9, the low bit/10 of the color codes. case "$1" in black|BLACK) echo "0";; red|RED) echo "1";; green|GREEN) echo "2";; yellow|YELLOW) echo "3";; blue|BLUE) echo "4";; magenta|MAGENTA) echo "5";; cyan|CYAN) echo "6";; white|WHITE) echo "7";; # What's 8? dtterm(5) doesn't say. default|DEFAULT) echo "9";; ?*) echo "9";; # Cop out. esac } # Convenience variables. RETURN_STRING="" # The future return value. BACKGROUND="4" FOREGROUND="3" ESCAPE="" CTRL_G="" # Main loop. while true do case "$1" in title) RETURN_STRING="${RETURN_STRING}${ESCAPE}]0;$2${CTRL_G}" shift 2;; iconify) RETURN_STRING="${RETURN_STRING}${ESCAPE}[2t" shift 1;; deiconify) RETURN_STRING="${RETURN_STRING}${ESCAPE}[1t" shift 1;; move) # X = $2, Y = $3 RETURN_STRING="${RETURN_STRING}${ESCAPE}[3;$2;$3t" shift 3;; resize) # H = $2, W = $3 RETURN_STRING="${RETURN_STRING}${ESCAPE}[4;$2;$3t" shift 3;; front) RETURN_STRING="${RETURN_STRING}${ESCAPE}[5t" shift 1;; back) RETURN_STRING="${RETURN_STRING}${ESCAPE}[6t" shift 1;; refresh|redraw) RETURN_STRING="${RETURN_STRING}${ESCAPE}[7t" shift 1;; bg|background) COLOR=$(color_low $2) RETURN_STRING="${RETURN_STRING}${ESCAPE}[${BACKGROUND}${COLOR}m" shift 2;; fg|foreground) COLOR=$(color_low $2) RETURN_STRING="${RETURN_STRING}${ESCAPE}[${FOREGROUND}${COLOR}m" shift 2;; ?*) # Who knows. Keep going, but complain. echo "${0}: I do not understand ${1}." 1>&2 shift 1;; esac if [ -z "$1" ] then break fi done print -n $RETURN_STRING #EOF