[alt.sources] pmwindow 1.0 - poor man's

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (09/03/90)

Here's pmwindow 1.0, a primitive windowing system for text terminals. It
works with at least several VT compatibles and other terminals; anything
with a change-scrolling-region command is good enough. pmwindow doesn't
have all (any?) of the fancy features of most windowing systems, but
it's FAST. It scrolls text like there's no tomorrow.

pmwindow uses pty to do the dirty work; pty, which should appear early
this week on comp.sources.unix, works on mostly any BSD variant.

Send comments to me or to alt.sources.d.

---Dan

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README pmwindow termcap kill0.c tcs.c
# Wrapped by brnstnd@kramden on Mon Sep  3 08:06:16 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1893 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XThis is pmwindow, the poor man's windowing system.
X
XIt has one big advantage over every other window system I've seen: it's
Xvery fast. If you're used to characters slowly marching up the screen
Xevery time you press return, you'll be pleasantly surprised to see
Xpmwindow run. I use it whenever I need to see two things at once on a
Xtext display; I can't stand the slowness of other window systems.
X
XOf course, pmwindow is also the smallest window system known to man.
X
XOther than that, it's pretty poor.
X
XThis is pmwindow version 1.0, 9/3/90, by Daniel J. Bernstein.
Xpmwindow is public domain.
X
X
XRequirements:
X
X  A 24-line screen. pmwindow has the numbers hardwired.
X
X  A termcap entry with ``cs'', change scrolling region.
X
X  A termcap entry whose ``cl'' doesn't destroy the entire screen. The
X  termcap file provided here works for generic VT compatibles; you may
X  have to rewrite your termcap entry along the same lines.
X
X  The pty program, including pty, sess, tty, disconnect, reconnect.
X
X  printenv, tr, grep, sh, echo with -n, sed, clear, stty, csh.
X
X  tcs and kill0. These programs are provided inside this package: just
X  cc -o kill0 kill0.c; cc -o tcs tcs.c -ltermcap.
X
X
XTo use pmwindow, just type pmwindow. Don't be alarmed by delays:
Xpmwindow is a shell script. Inside the windows, type the usual ^D to
Xexit the shell, or ``disconnect'' to switch to the other screen. (You
Xmay want to give ``disconnect'' a nicer alias.)
X
XCaveats:
X
X  When switching windows, pmwindow always leaves you in the bottom right
X  hand corner of the old window. This is usually, but not always,
X  correct.
X
X  When one window exits, pmwindow changes back to full-screen. This is
X  pretty much guaranteed to put the cursor at the wrong spot. (It does
X  pass WINCH through correctly, courtesy pty, so editors will resize
X  appropriately.)
X
X  You won't see output in the window you're not using.
X
X
XGood luck!
END_OF_FILE
if test 1893 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'pmwindow' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pmwindow'\"
else
echo shar: Extracting \"'pmwindow'\" \(867 characters\)
sed "s/^X//" >'pmwindow' <<'END_OF_FILE'
X#!/bin/sh
Xotc=$TERMCAP;TERMCAP=`printenv TERMCAP|tr : '\012'|grep -v '^cs='|tr '\012' :`
Xexport TERMCAP
Xs1=`sess -qJ sh -c 'echo -n $$;tty;disconnect;exec csh -f'|sed 's-/dev/tty- -'`
Xs2=`sess -qJ sh -c 'echo -n $$;tty;disconnect;exec csh -f'|sed 's-/dev/tty- -'`
Xexport s1; p1=`printenv s1|sed 's/ .*//'`; s1=`printenv s1|sed 's/.* //'`
Xexport s2; p2=`printenv s2|sed 's/ .*//'`; s2=`printenv s2|sed 's/.* //'`
XTERMCAP=$otc
X
Xclear; stty rows 11; stty raw cbreak -echo
Xwhile :
Xdo
X  tcs 10 0
X  sess -qJ sh -c 'reconnect "'"$s1"'" >/dev/null 2>&1'
X  kill0 $p1 || { die=1; break; }
X  tcs 22 12
X  sess -qJ sh -c 'reconnect "'"$s2"'" >/dev/null 2>&1'
X  kill0 $p2 || { die=2; break; }
Xdone
X
Xstty rows 24; tcs 23 0
Xcase $die in
X1) sess -qJ sh -c 'reconnect "'"$s2"'" >/dev/null 2>&1' ;;
X2) sess -qJ sh -c 'reconnect "'"$s1"'" >/dev/null 2>&1' ;;
Xesac
Xstty -raw -cbreak echo
END_OF_FILE
if test 867 -ne `wc -c <'pmwindow'`; then
    echo shar: \"'pmwindow'\" unpacked with wrong size!
fi
chmod +x 'pmwindow'
# end of 'pmwindow'
fi
if test -f 'termcap' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'termcap'\"
else
echo shar: Extracting \"'termcap'\" \(421 characters\)
sed "s/^X//" >'termcap' <<'END_OF_FILE'
XvP|vt-pm:al=3\E[L:bl=^G:bs:cd=50\E[J:ce=3\E[K:cl=50^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J^J\E[;H:cm=5\E[%i%2;%2H:co#80:cs=5\E[%i%d;%dr\E[?6h:dc=2\E[P:dl=3\E[M:do=3\E[B:le=2\E[D:li#24:me=2\E[m:nd=2\E[C:pt:se=2\E[m:sf=2^J:sg=0:so=2\E[1m:sr=5\EM:ta=^I:ue=2\E[m:ug=0:up=2\E[A:us=2\E[4m:is=\E7\E[1;24r\E>\E[?1;3;4;5l\E[6;7;8h\E8:if=/usr/lib/tabset/vt100:rs=\E7\E[1;24r\E>\E[?1;3;4;5l\E[6;7;8h\E8:ho=5\E[;H:cr=^M:am:
END_OF_FILE
if test 421 -ne `wc -c <'termcap'`; then
    echo shar: \"'termcap'\" unpacked with wrong size!
fi
# end of 'termcap'
fi
if test -f 'kill0.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kill0.c'\"
else
echo shar: Extracting \"'kill0.c'\" \(74 characters\)
sed "s/^X//" >'kill0.c' <<'END_OF_FILE'
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X exit(kill(atoi(argv[1]),0));
X}
END_OF_FILE
if test 74 -ne `wc -c <'kill0.c'`; then
    echo shar: \"'kill0.c'\" unpacked with wrong size!
fi
# end of 'kill0.c'
fi
if test -f 'tcs.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tcs.c'\"
else
echo shar: Extracting \"'tcs.c'\" \(336 characters\)
sed "s/^X//" >'tcs.c' <<'END_OF_FILE'
Xoutc(ch)
Xchar ch;
X{
X putchar(ch);
X}
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X char bp[1024];
X char c[256];
X char *cptr;
X
X tgetent(bp,getenv("TERM"));
X cptr = c;
X if (tgetstr("cs",&cptr))
X   tputs(tgoto(c,atoi(argv[1]),atoi(argv[2])),1,outc);
X cptr = c;
X if (tgetstr("cm",&cptr))
X   tputs(tgoto(c,0,atoi(argv[1])),1,outc);
X exit(0);
X}
END_OF_FILE
if test 336 -ne `wc -c <'tcs.c'`; then
    echo shar: \"'tcs.c'\" unpacked with wrong size!
fi
# end of 'tcs.c'
fi
echo shar: End of shell archive.
exit 0