Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear the console #10

Closed
zygimantus opened this issue Jan 26, 2018 · 2 comments
Closed

Clear the console #10

zygimantus opened this issue Jan 26, 2018 · 2 comments

Comments

@zygimantus
Copy link

Is there a way or a feature to clear the console using this library?
Standard way using System.out.print("\033[H\033[2J"); is not working.

@siordache
Copy link
Member

Currently, the API doesn't provide a way to clear the console. I will add this feature in the next release.
As a workaround, you can use the clearScreen method shown in the code below:

import org.beryx.textio.TextIO;
import org.beryx.textio.TextIoFactory;
import org.beryx.textio.TextTerminal;
import org.beryx.textio.jline.JLineTextTerminal;
import org.beryx.textio.swing.SwingTextTerminal;

public class ClearTest {
    public static void clearScreen(TextTerminal terminal) {
        if (terminal instanceof JLineTextTerminal) {
            terminal.print("\033[H\033[2J");
        } else if (terminal instanceof SwingTextTerminal) {
            ((SwingTextTerminal) terminal).resetToOffset(0);
        }
    }

    public static void main(String[] args) {
        TextIO textIO = TextIoFactory.getTextIO();
        TextTerminal terminal = textIO.getTextTerminal();

        String user = textIO.newStringInputReader().read("Username");

        clearScreen(terminal);

        int age = textIO.newIntInputReader().read("Age");

        textIO.dispose();
    }
}

@zygimantus
Copy link
Author

Thank you. Your given method saves the day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants