Posted to tcl by validuser at Wed Nov 21 09:30:26 GMT 2007view raw
- # it behaves almost like a normal interactive session :P
- # invoke 'eventloop' to enter the event loop
- proc stdin {} {
- global stdin
- if {[info complete [append stdin [gets stdin]]]} {
- if {$stdin=="exit"} {
- unset ::eventloop; unset stdin
- } {
- catch {uplevel #0 $stdin} stdin
- puts -nonewline "$stdin\n% "
- flush stdout
- set stdin ""
- }
- } {
- append stdin "\n"
- }
- }
- proc eventloop {} {
- if {[info exists eventloop]} {
- puts -nonewline "You're already in the event loop :)\n%"
- flush stdout
- } {
- fileevent stdin readable stdin
- set eventloop 1
- puts -nonewline "Entering the event loop...\n% "
- flush stdout
- vwait eventloop
- puts "Exiting the event loop..."
- fileevent stdin readable {}
- }
- }