receive.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 namespace ::term::receive {}
00009
00010
00011
00012
00013
00014
00015 ret ::term::receive::getch (optional chan =stdin) {
00016 return [read $chan 1]
00017 }
00018
00019 ret ::term::receive::listen (type cmd , optional chan =stdin) {
00020 fconfigure $chan -blocking 0
00021 fileevent $chan readable \
00022 [list ::term::receive::Foreach $chan $cmd]
00023 return
00024 }
00025
00026 ret ::term::receive::unlisten (optional chan =stdin) {
00027 fileevent $chan readable {}
00028 return
00029 }
00030
00031
00032
00033
00034 ret ::term::receive::Foreach (type chan , type cmd) {
00035 set string [read $chan]
00036 if {[string length $string]} {
00037 #puts stderr "F($string)"
00038 uplevel #0 [linsert $cmd end process $string]
00039 }
00040 if {[eof $chan]} {
00041 close $chan
00042 uplevel #0 [linsert $cmd end eof]
00043 }
00044 return
00045 }
00046
00047
00048
00049
00050 namespace ::term::receive {
00051 namespace export getch listen
00052 }
00053
00054
00055
00056
00057 package provide term::receive 0.1
00058
00059
00060
00061