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

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


#!/dis/sh
# simple tk application: execute commands entered by
# the user and place the output in a scrollable text widget
{
	load std
	load tk
	pctl newpgrp
	wid=${tk window 'A shell application'}
	{while {} {tk winctl $wid ${recv $wid}}} &	# default window handling

	fn x { a := $*; or {tk $wid $a} {echo error on tk cmd $"a':' $status } }
	nl:='
'
	x entry .e
	x frame .f
	x scrollbar .f.s -orient vertical -command {.f.t yview}
	x text .f.t -yscrollcommand {.f.s set}
	x pack .f.s -side left -fill y
	x pack .f.t -side top -fill both -expand 1
	x pack .e -side top -fill x
	x pack .f -side top -fill both -expand 1
	x pack propagate . 0
	x bind .e '<Key-'^$nl^'>' {send event enter}
	x update

	chan event
	tk namechan $wid event event
	while {} {
		{} ${recv event}
		cmd := ${tk $wid .e get}
		text := "{
				rescue '*' {echo 'execution failed: got exception' $exception} {
					'{'^$cmd^'}'
				}
		}
		x .f.t delete 1.0 end
		x .f.t insert 1.0 ''''^$text
		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.