非交互式 tclsh 可以变成交互式吗?

问题描述 投票:0回答:1

在开发 Tcl 代码时,我发现 tclsh 的交互式工具非常有用,我经常会交互式地启动 tclsh,从文件中

source
代码,并从那里继续运行和调试。

我想知道的是:有没有办法从非交互式的 tclsh 实例进入交互式 shell(比如因为它是使用脚本文件参数运行的)?我知道有一个

tcl_interactive
变量,可以设置,但这样做不会导致交互式提示。

我希望能够在同一个进程和终端中执行此操作(尽管 Tkcon 确实很棒)。

(我猜想棘手的事情是将 Tcl 的输入从指定的脚本文件切换到终端/pty 的 stdin。这可能需要 Expect 的魔力才能工作。我也考虑过使用

.tclshrc
的一些技巧,但是这会变得混乱;我希望
tclsh
让您在命令行或通过环境变量指定一个 rc 文件。)

debugging tcl stdin interactive tclsh
1个回答
0
投票

您可以启动 tclreadline REPL 循环:

proc poll {} {
    puts "doing something"
    if {[incr ::pollnum] == 3} {
        package require tclreadline
        tclreadline::Loop
    }
    after 2000 poll
}

poll
after 2000

vwait forever
doing something
doing something
doing something
tclsh8.7 [/tmp] puts "hello, repl"
hello, repl
tclsh8.7 [/tmp] 
© www.soinside.com 2019 - 2024. All rights reserved.