Reputation: 1914
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?
Upvotes: 22
Views: 7513
Reputation: 8086
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:
/open DEFAULT
void cls() { for( int i=0; i < 50; i++ ) { System.out.println(); } }
/set start -retain <PATH+FILE_NAME[+EXT]>
/reset
NOTE: Call cls()
, not just cls
.
EDIT: Edit the number 50 as per your screen.
Upvotes: 0
Reputation: 20901
Use the Control Key+L or l (lower case L) to clear the JShell console.
Upvotes: 17
Reputation: 4875
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
Upvotes: 2
Reputation: 1010
In macOS terminal, you could use the CMD+K shortcut to clear the JShell console.
Upvotes: 3
Reputation: 1914
-> /cls
Upvotes: 0
Reputation: 95968
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.
Upvotes: 7