You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
package Application;
|
|
|
|
import java.io.InputStream;
|
|
import java.io.PrintStream;
|
|
import java.util.Scanner;
|
|
|
|
public class Cli {
|
|
|
|
private boolean isClearConsoleActive = true;
|
|
|
|
private PrintStream printStream;
|
|
private InputStream inputStream;
|
|
private Scanner scanner;
|
|
|
|
public Cli(PrintStream printStream, InputStream inputStream) {
|
|
this.printStream = printStream;
|
|
this.inputStream = inputStream;
|
|
this.scanner = new Scanner(inputStream);
|
|
isClearConsoleActive = true;
|
|
}
|
|
|
|
public PrintStream getPrintStream() {
|
|
return this.printStream;
|
|
}
|
|
|
|
public Scanner getScanner(){
|
|
return this.scanner;
|
|
}
|
|
|
|
public void clearConsole(){
|
|
if(!isClearConsoleActive)
|
|
return;
|
|
try{
|
|
String operatingSystem = System.getProperty("os.name");//Check the current operating system
|
|
|
|
if(operatingSystem.contains("Windows")){
|
|
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "cls");
|
|
Process startProcess = pb.inheritIO().start();
|
|
startProcess.waitFor();
|
|
} else {
|
|
ProcessBuilder pb = new ProcessBuilder("clear");
|
|
Process startProcess = pb.inheritIO().start();
|
|
|
|
startProcess.waitFor();
|
|
}
|
|
}catch(Exception e){
|
|
this.getPrintStream().println(e);
|
|
}
|
|
}
|
|
|
|
public void setClearConsoleActive(boolean clearConsoleActive) {
|
|
isClearConsoleActive = clearConsoleActive;
|
|
}
|
|
|
|
}
|