轻灵,内省,质朴,有为

在Tcl中怎么实现屏幕随时的交互?类似于在shell中top后,随时按q就可以退出的

+1 投票

@流吾思  在QQ群里如此提问。

实现的关键点是:

  • 异步的标准输入stdin
  • 读取单个字符,而不是整行(借助 stty 命令)
代码: async-stdin.tcl
proc onkeyup {chan args} {
  set data [read $chan 512]
  puts $data
  if {$data eq "q"} {
    exit
  }
}

exec stty raw -echo <@ stdin
fconfigure stdin -blocking 0
fileevent stdin readable [list onkeyup stdin]

puts "Press 'q' to exit!"

vwait forever


最新提问 8月 28, 2015 分类:语法命令 | 用户: 风行水上 (-30 分)
修改于 8月 28, 2015 用户:风行水上

登录 或者 注册 后回答这个问题。

...