--- /dev/null
+#!/usr/bin/wishx
+
+source lib.tcl
+
+proc widgets {} {
+ set sizes [exec ./gui-plan-bot --sizes]
+ frame .picture -background {} \
+ -width [lindex $sizes 0] \
+ -height [lindex $sizes 1]
+ pack .picture
+ tkwait visibility .picture
+}
+
+proc bgerror {emsg} {
+ global errorCode errorInfo
+ catch {
+ puts stderr "UNEXPECTED BACKGROUND ERROR\n"
+ puts stderr "$errorCode\n$errorInfo\n$emsg"
+ }
+ exit 16
+}
+
+proc gui-pipe-readable {args} {
+ global gui_pipe
+ while {[gets $gui_pipe l] >= 0} {
+ puts "<gui-plan $l"
+ }
+ if {[eof $gui_pipe]} {
+ close $gui_pipe
+ error "gui-plan crashed"
+ }
+}
+
+proc engage {} {
+ global gui_pipe server port
+ global sconn
+
+ set sconn [socket $server $port]
+ fconfig-trainproto $sconn
+
+ set cmdl [list ./gui-plan-bot [winfo id .picture] @$server,$port]
+ lappend cmdl 2>@ stderr
+ set gui_pipe [open |$cmdl r]
+
+ puts stderr "running $cmdl"
+ fconfigure $gui_pipe -blocking no
+ fileevent $gui_pipe readable gui-pipe-readable
+
+ start_commandloop
+}
+
+proc main {} {
+ setting server railway {[[0-9a-z:].*}
+ parse-argv {}
+ widgets
+ engage
+}
+
+main