Snippet to easily invoke terminal escapes. Follow the code down here #Console.java
- In IntelliJ, go to
File ->
Project Structure` - Click on Project
Settings
->Libraries
- Press the
+
button ->From Maven...
- Type the following libraries and add them.
net.java.dev.jna:jna-platform:5.4.0
net.java.dev.jna:jna:5.4.0
- Create a new class, name it
Console.java
- Paste the code down below
- Type
Console.viewColors();
in any line to see if it works. - Run your code in IntelliJ or press
Ctrl + F5
. - After running, copy the first line you see in the console.
- Open
cmd
and paste the code there. It should look similar to this.
C:\Users\Kao> cd C:\Users\Kao\IdeaProjects\kt\Week 7
C:\Users\Kao\IdeaProjects\kt\Week 7> "C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\jbr\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\lib\idea_rt.jar=55445:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\Kao\IdeaProjects\kt\Week 7\out\production\Week 7;C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\plugins\Kotlin\kotlinc\lib\kotlin-stdlib.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\plugins\Kotlin\kotlinc\lib\kotlin-reflect.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\plugins\Kotlin\kotlinc\lib\kotlin-test.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\plugins\Kotlin\kotlinc\lib\kotlin-stdlib-jdk7.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\plugins\Kotlin\kotlinc\lib\kotlin-stdlib-jdk8.jar;C:\Users\Kao\.m2\repository\net\java\dev\jna\jna-platform\5.4.0\jna-platform-5.4.0.jar;C:\Users\Kao\.m2\repository\net\java\dev\jna\jna\5.4.0\jna-5.4.0.jar" com.hizamakura.kao.ScrabbleKt
Jumps the cursor to the x and y position.
Console.gotoXY(5, 5);
Clears the entire screen.
Console.cls();
Moves the cursor at the top left.
Console.home();
Clears everything starting from the cursor.
Console.eos();
Clears text starting from cursor to the end of line.
Console.eol();
Sets the color of the text according to the number.
/*
0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green 10 = Light Green
3 = Aqua 11 = Light Aqua
4 = Red 12 = Light Red
5 = Purple 13 = Light Purple
6 = Yellow 14 = Light Yellow
7 = White 15 = Bright White
*/
Console.color(3);