when using "console": "integratedTerminal"
in a launch.json the program output is redirected to the integrated terminal. However, after terminating a debug session and starting another one, the terminal is re-used which can be pretty annoying.
I have not found a way to make VSCode clear the terminal -- it is possible to clear the panel in tasks.json with the clear: true
property, this however only works for tasks such as the build task but has no effect on the debug panel.
Help is greatly appreciated.
Thanks in advance
-Simon
this however only works for tasks such as the build task but has no effect on the debug panel.
The 'Debug Console' should be new text every session.
If you would like to redirect the terminal output to the Debug Console you can use the following properties for your launch.json
file:
internalConsoleOptions
Controls when the internal debug console should open.
redirectOutput
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"internalConsoleOptions": "openOnSessionStart",
"redirectOutput": true
}
]
Both of these used in tandem will open the 'Debug Console' instead of terminal and just provide the necessary output; though it still sends to terminal should you still want it:
Another option is to not use the terminal at all:
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole",
}
]
Meaning, it does not send to (or use) your integrated terminal at all and only opens the Debug Console, which doesn't show any cd
like statements or executable overhead and no previous history
Shorcuts (definitely not as user friendly):
Terminal: Relaunch Active Terminal
CommandId: workbench.action.terminal.relaunch
Terminal: Clear
CommandId: workbench.action.terminal.clear
These options don't answer the question "how to clear the terminal when debug starts", but options for those new to vscode to consider as alternatives. I'm not so sure they feel the terminal is appropriate for debugging, because we have a debug console and debug/run panel. The reason this can be complicated is because extensions use their own output channels for debugging. For example, the python uses a completely different terminal than say Code Runner. Same for javascript and then there is native support.
There is a new setting due in v1.55:
debug.terminal.clearBeforeReusing
Some debug extension allow to launch debuggees in VS Code's integrated terminal. In order keep the number of integrated terminals small, VS Code tries to reuse a terminal if it is not blocked by a still running command. A consequence of this approach is that previous commands and program output will remain visible in the terminal which is sometimes confusing.
In this release we've introduced a new feature to automatically clear the integrated terminal before starting a new debug session. The feature is controlled by the new setting
debug.terminal.clearBeforeReusing
.
from https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_55.md#new-setting-for-clearing-a-terminal-before-launching-a-debuggee
You can clear the terminal using a preLaunchTask
:
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"preLaunchTask": "Clear terminal",
"runtimeVersion": "15.14.0",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "start"],
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
}
]
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Clear terminal",
"command": "echo ${command:workbench.action.terminal.clear}"
}
]
}
There is one caveat though: it will clear the active terminal. So if you switched to a different terminal after completing the task, this will clear that terminal instead... I have not found a way to target a specific terminal window, and I don't think it's possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With