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?
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.
在macOS终端中,您可以使用CMD + K快捷方式清除JShell控制台。
使用Control Key + L或l(小写L)清除JShell控制台。
-> /cls
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
OPTION A:
Create a method: void cls() { for( int i=0; i < 50; i++ ) { System.out.println(); } }
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.
Use CTRL+L to clear Jshell screen in Windows 11 OS.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.