コマンドプロンプトMyShell >
を使用して、インタラクティブなTCLセッションを実装するだけのコードです。TCLは-nohangオプションのようなコマンドを取得しますか?
puts -nonewline stdout "MyShell > "
flush stdout
catch { eval [gets stdin] } got
if { $got ne "" } {
puts stderr $got
}
このコードは、末端MyShell >
を促し、入力ボタンをヒットするのを待ちます。それがヒットしないうちにコードは何もしません。これはコマンドgets
の動作です。
gets
コマンドの代わりに、coolget
などがあります。 coolget
コマンドは、Enterボタンを待つべきではなく、ヒットしたときに呼び出されるスロットを登録し、実行を続行するだけです。希望のコードは次のようになります。ここでは
proc evaluate { string } \
{
catch { eval $string } got
if { $got ne "" } {
puts stderr $got
}
}
puts -nonewline stdout "MyShell > "
flush stdout
coolgets stdin evaluate; # this command should not wait for the enter button
# here goes some code which is to be executed before the enter button is hit
私は必要なものである:
proc prompt { } \
{
puts -nonewline stdout "MyShell > "
flush stdout
}
proc process { } \
{
catch { uplevel #0 [gets stdin] } got
if { $got ne "" } {
puts stderr $got
flush stderr
}
prompt
}
fileevent stdin readable process
prompt
while { true } { update; after 100 }