Wish there be a setting that can clear the terminal automatically every time I run the java project instead of manually running clear command in terminal.
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
}
}
The terminal show all previous results:

Terminal clears the previous information and only keep the latest running results
None
The debugger is just responsible for generating the program command lines, and then send to the VS Code client to execute. The debugger doesn't actually have much control over the terminal. To achieve the feature you mentioned, one possible approach is to add an extra "clear" command before the normal command line for that.
The debugger is just responsible for generating the program command lines, and then send to the VS Code client to execute. The debugger doesn't actually have much control over the terminal. To achieve the feature you mentioned, one possible approach is to add an extra
"clear"command before the normal command line for that.
Do you mean to type clear in Terminal before run the project every time? This indeed clears the Terminal, but OP would like to clear the terminal each time when run in java automatically, could this function be achievable in launch.json or Settings.json?

No such setting yet. Have a look further. Seems this requires the VS Code client to provide such capability.
Currently the debugger is using the DAP protocol to send the command lines to the VS Code client, but there is no way to print an extra "clear" command at the head. See https://microsoft.github.io/debug-adapter-protocol/specification#Reverse_Requests_RunInTerminal. Need extend the DAP protocol to add a new property such as "clearTerminal": boolean for such requirement. Opened a request at https://github.com/microsoft/debug-adapter-protocol/issues/165
This sort of relates to what I was talking about in #906, but I suppose clearing the terminal is technically separate from hiding the launch command. Makes sense to have it as separate options.
When suggesting code changes in #906, I forgot that you're using DAP, but now I realise that the feature requires upstream changes. Perhaps DAP could provide a feature that satisfies both issues, either at the same time or through two different options?
No such setting yet. Have a look further. Seems this requires the VS Code client to provide such capability.
Currently the debugger is using the DAP protocol to send the command lines to the VS Code client, but there is no way to print an extra "clear" command at the head. See https://microsoft.github.io/debug-adapter-protocol/specification#Reverse_Requests_RunInTerminal. Need extend the DAP protocol to add a new property such as
"clearTerminal": booleanfor such requirement. Opened a request at microsoft/debug-adapter-protocol#165
Got it. Thanks for your reply.
Regarding the issue of hiding the launching command, i don't think any OS terminal offers such capability.
Can you share the reason why you don't like explicitly displaying the command line in terminal?
Regarding the issue of hiding the launching command, i don't think any OS terminal offers such capability.
Can you share the reason why you don't like explicitly displaying the command line in terminal?
I don't know, this is the original post: https://stackoverflow.com/questions/64947409/how-do-i-clear-the-terminal-in-vscode-programmatically/64961955#64961955
...i don't think any OS terminal offers such capability.
True, which is why #906 is about a pseudoterminal, not a regular terminal. By which I mean that the extension (or perhaps it should be implemented in DAP) could hide the launch command by only printing the stdout of the program being debugged, and redirecting user input from the pseduoterminal to the stdin of the program.
Can you share the reason why you don't like explicitly displaying the command line in terminal?
I mentioned some reasons in #906, but to clarify: I believe the launch command just adds unnecessary clutter and verbosity to the debugging experience, since 99% of the time, you're not interested in what commands where used to launch your program. At first it might not seem that bad, but when you add lots of VM args and have long paths to your program, the terminal just becomes too cluttered. Depending on the program you're developing, this may or may not be a problem, but for CLI applications it's a very bad user experience to have to separate the program output from the random noise of the launch command. As I've said in #906, the Eclipse IDE already provides a pseudoterminal for Java programs being debugged by default, see the image I posted there.
Here are some links to reddit posts where several other users have been asking for this feature:
@0dinD Thanks for providing such information, I get your point. Currently, the debugger doesn't take care of client-side rendering, it just delegates the output to the internal debug console or terminal via DAP. To support the pseudo-terminal, we need to use a separate process on the client side to handle starting the program in the pseudo-terminal and then attaching your JVM debug port to the debugger.
To support the pseudo-terminal, we need to use a separate process on the client side to handle starting the program in the pseudo-terminal and then attaching your JVM debug port to the debugger.
Yeah, that's where I was going with #906. I realise now though that it might require upstream changes in DAP to be implemented in a clean way. Now that I think about it this would be a useful thing for other debug extensions like C/C++, Python etc to also easily be able to specify an option for hiding launch commands via a pseudoterminal.
If this is the case, will you communicate the request with the DAP team? Or should I add this to the discussion over at microsoft/debug-adapter-protocol#165?
No, it doesn't need the additional support of DAP. I prefer to keep DAP for physical terminal. for pseudo terminal, we will not use DAP to send commands to start the program, but use external process to handle it. The debugger will attach the JVM process similarly to remote debugging.
This is supported by VS Code 1.55.0 and above.
The user setting is "debug.terminal.clearBeforeReusing".