Plan 9 from Bell Labs’s /usr/web/sources/contrib/rog/sh-examples/animate.sh

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/dis/sh
# use tk to show rectangles output from a rectangle fitting program.
# example of how a shell script can be knocked up to display
# graphically the output of a testing module that outputs only text.
# in this example, the command being tested is rectfind which,
# given two arguments (minx miny), the minimum size of a rectangle
# to fit, reads rectangles from stdin and writes to stdout all the rectangles
# it has found, prefixed by a colour name (e.g. red, orange)
load expr
args=$*
pctl newpgrp
fn debug {
	echo $* >[1=2]
}
ifs='
 	'
nl='
'
{
	rargs := ()
	rnum := 1
	getlines {
		rargs=$rargs $line
		echo $rnum blue $line
		rnum=${expr $rnum 1 +}
	}
	echo ${join $nl $rargs} | rectfind $args | getlines {
		echo $rnum $line
		rnum=${expr $rnum 1 +}
	}
} | {
	load tk
	wid := ${tk window 'Test rects'}
	while {} {tk winctl $wid ${recv $wid}} &
	fn x { a := $*; or {tk $wid $a} {echo error on tk cmd $"a':' $status }}
	x canvas .c -width 500 -height 400
	x pack .c
	chan stdout; tk namechan $wid stdout
	x bind .c '<Button-1>' {send stdout %x %y}
	while {} {echo ${recv stdout}} &
	x update
	getlines {
		(rnum col r) := ${split $line}
		lastcmd = x .c create rectangle $r -fill $col -tags t^$rnum
		$lastcmd
		x update
		if {! ~ $col blue} {
			sleep 1
			x .c delete t^$rnum
			x update
		}
	}
	$lastcmd
	x update
	echo finished >[2=1]
	< /dev/cons getlines {
		x ${unquote $line}
		x update
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.