diff --git a/src/main/java/Application/Cli.java b/src/main/java/Application/Cli.java index b786871..2b93962 100644 --- a/src/main/java/Application/Cli.java +++ b/src/main/java/Application/Cli.java @@ -23,4 +23,23 @@ public class Cli { public Scanner getScanner(){ return this.scanner; } + + public void clearConsole(){ + 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); + } + } } diff --git a/src/test/java/Application/CliTest.java b/src/test/java/Application/CliTest.java index bc81251..fbc4306 100644 --- a/src/test/java/Application/CliTest.java +++ b/src/test/java/Application/CliTest.java @@ -10,6 +10,7 @@ import java.io.InputStream; import java.io.PrintStream; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class CliTest { @@ -45,4 +46,10 @@ class CliTest { void getScanner() { assertEquals(cli.getScanner().next(), "Test"); } + + //Cannot test because it uses external processes + @Test + void clearConsole() { + assertTrue(true); + } } \ No newline at end of file