Index: library/lib/nx-shell.tcl =================================================================== diff -u -r4b929805d1acbf4fd07b6a969c2223467416523b -r2a5945f098b50d909d57fb3d3abfaf44608c0ac8 --- library/lib/nx-shell.tcl (.../nx-shell.tcl) (revision 4b929805d1acbf4fd07b6a969c2223467416523b) +++ library/lib/nx-shell.tcl (.../nx-shell.tcl) (revision 2a5945f098b50d909d57fb3d3abfaf44608c0ac8) @@ -2,6 +2,57 @@ package provide nx::shell 1.0 +nx::Object create ::nx::shell2 { + + :public object method onRead {{chan stdin}} { + append :line [read $chan] + if {[eof $chan]} { + fileevent $chan readable {} + set :forever eof + } + if {${:line} eq "\n"} { + unset :line + :prompt + return + } + if {[info complete ${:line}]} { + set script [list catch [string trim ${:line}] [current]::result [current]::opts] + set r [uplevel #0 $script] + if {$r} { + puts stdout [dict get ${:opts} -errorinfo] + unset :opts; + } else { + puts stdout ${:result} + unset :result + } + unset :line + if {![info exists :forever]} { + :prompt + } + } + } + + :public object method prompt {{chan stdout}} { + puts -nonewline $chan "% " + flush $chan + } + + :public object method run {argc argv} { + if {$argc == 0} { + :prompt stdout + fconfigure stdin -blocking 0 -buffering line + fileevent stdin readable [list [current] onRead] + vwait :forever + fileevent stdin readable {} + exit + } else { + set ::argv [lassign $argv argv0] + incr ::argc -1 + uplevel #0 [list source $argv0] + } + } +} + nx::Object create ::nx::shell { :public object method run {argc argv} { if {$argc == 0} { Index: library/xotcl/xotclsh.in =================================================================== diff -u -r286f946169fb15fa210aca115420fa3142c68ffa -r2a5945f098b50d909d57fb3d3abfaf44608c0ac8 --- library/xotcl/xotclsh.in (.../xotclsh.in) (revision 286f946169fb15fa210aca115420fa3142c68ffa) +++ library/xotcl/xotclsh.in (.../xotclsh.in) (revision 2a5945f098b50d909d57fb3d3abfaf44608c0ac8) @@ -23,4 +23,4 @@ namespace import -force ::xotcl::* -nx::shell run $argc $argv +nx::shell2 run $argc $argv Index: library/xotcl/xowish.in =================================================================== diff -u -r286f946169fb15fa210aca115420fa3142c68ffa -r2a5945f098b50d909d57fb3d3abfaf44608c0ac8 --- library/xotcl/xowish.in (.../xowish.in) (revision 286f946169fb15fa210aca115420fa3142c68ffa) +++ library/xotcl/xowish.in (.../xowish.in) (revision 2a5945f098b50d909d57fb3d3abfaf44608c0ac8) @@ -24,4 +24,4 @@ namespace import -force ::xotcl::* -nx::shell run $argc $argv +nx::shell2 run $argc $argv Index: nxsh.in =================================================================== diff -u -r4b929805d1acbf4fd07b6a969c2223467416523b -r2a5945f098b50d909d57fb3d3abfaf44608c0ac8 --- nxsh.in (.../nxsh.in) (revision 4b929805d1acbf4fd07b6a969c2223467416523b) +++ nxsh.in (.../nxsh.in) (revision 2a5945f098b50d909d57fb3d3abfaf44608c0ac8) @@ -20,4 +20,4 @@ namespace import -force ::nx::* -nx::shell run $argc $argv +nx::shell2 run $argc $argv Index: nxwish.in =================================================================== diff -u -r4b929805d1acbf4fd07b6a969c2223467416523b -r2a5945f098b50d909d57fb3d3abfaf44608c0ac8 --- nxwish.in (.../nxwish.in) (revision 4b929805d1acbf4fd07b6a969c2223467416523b) +++ nxwish.in (.../nxwish.in) (revision 2a5945f098b50d909d57fb3d3abfaf44608c0ac8) @@ -23,4 +23,4 @@ namespace import -force ::nx::* -nx::shell run $argc $argv +nx::shell2 run $argc $argv