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} {