【问题标题】:How can I use the same / existing external terminal (session) when debugging?调试时如何使用相同/现有的外部终端(会话)?
【发布时间】:2021-11-05 12:14:13
【问题描述】:

每次我调试(使用外部终端)时,它都会打开一个新会话。

  • 是否可以重复使用相同的窗口/会话?
  • 或者如果不关闭当前窗口,使其不会继续打开新窗口?

类似的问题与内部终端有关。 我在 macOS 上使用 iTerm2。

这是我的 launch.json 配置:

{
    "version": "0.2.0",
    "configurations": [
      
        {
            "name": "Python: Current File (External)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal",
            "python": "/Users/josip/.virtualenvs/myproject-JnedzVU7/bin/python",
        },
        {
            "name": "Python: Current File",
            "type": "python",
            // "justMyCode": false,
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"

        },
    ]
}

【问题讨论】:

    标签: visual-studio-code vscode-debugger


    【解决方案1】:

    这个问题只存在于 iTerm,因为终端的一切都按预期工作,并且现有会话用于连续运行/调试执行。

    行为上的差异是由于将调试命令发送到外部终端的 AppleScript 的编写方式所致。 script for Terminal (readable gist) 包含用于查找可用会话并告诉应用程序使用该会话运行命令的逻辑。相反,script for iTerm (readable gist) 与发送命令以在 iTerm 中运行一样简单。

    虽然终端脚本具有确定要使用的正确会话和窗口的功能,但 iTerm 脚本只有以下功能(不包括相同的验证步骤):

    tell application "iTerm"
        activate
        set new_term to (create window with default profile)
        delay 1
        tell new_term
            tell the current session
                write text cmd
            end tell
        end tell
    end tell
    

    This is where the script is loaded and used to run the command in the configured terminal

    我已经扫描了iTerm scripting documentation,如果您想提出功能请求或提交包含更改的拉取请求,应该可以使用 iTerm API 复制终端行为。

    【讨论】:

      猜你喜欢
      • 2016-04-15
      • 1970-01-01
      • 2018-06-19
      • 2021-01-07
      • 1970-01-01
      • 2013-08-08
      • 2019-07-06
      • 1970-01-01
      相关资源
      最近更新 更多