问题
I didn't find any command to clear Java-9 JShell console. I also tried to clear the JShell Console through this program, but it doesn't work either.
import java.io.IOException;
class CLS {
public static void main(String... arg) throws IOException, InterruptedException {
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
}
}
I think we don't have that functionality available yet in the early access. Anyone got an idea?
回答1:
You can use the following command (reference):
System.out.print("\033[H\033[2J");
Example:
-> System.out.println("Hello, JShell!")
Hello, JShell!
-> System.out.println("How are you?")
How are you?
-> System.out.print("\033[H\033[2J");
Now you'll have a clear console.
回答2:
In macOS terminal, you could use the CMD+K shortcut to clear the JShell console.
回答3:
Use the Control Key+L or l (lower case L) to clear the JShell console.
回答4:
There is an issue about this Bug jshell tool: Clear screen command
for now, first exit jshell by
/exit
then
cls
if you want to reset use
/reset
回答5:
- I have added clear console command in JShell. You can download it from Try artifact
-> /cls
- It also supports maven in JShell.
回答6:
OPTION A:
Create a method: void cls() { for( int i=0; i < 50; i++ ) { System.out.println(); } }
and call it.
OPTION B:
To retain it for future sessions also, append the method to a startup script as follows:
- Create and save a file with following(retain any of yours):
/open DEFAULT
void cls() { for( int i=0; i < 50; i++ ) { System.out.println(); } }
- Run the script:
/set start -retain <PATH+FILE_NAME[+EXT]>
- Run command(save your work before using this command):
/reset
- Call the method.
NOTE: Call cls()
, not just cls
.
EDIT: Edit the number 50 as per your screen.
来源:https://stackoverflow.com/questions/36847804/how-to-clear-java-9-jshell-console