How to clear Java 9 JShell Console?

℡╲_俬逩灬. 提交于 2019-12-08 14:56:17

问题


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:

  1. 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(); } }

  1. Run the script: /set start -retain <PATH+FILE_NAME[+EXT]>
  2. Run command(save your work before using this command): /reset
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!