-
Notifications
You must be signed in to change notification settings - Fork 1
/
TerminalTools.java
64 lines (61 loc) · 1.82 KB
/
TerminalTools.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
public class TerminalTools {
public enum Color {
BLACK,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
WHITE
}
public static final String ESCAPE = "\u001b";
public static void moveUp(int spaces) {
System.out.print(ESCAPE + "[" + spaces + "A");
}
public static void moveDown(int spaces) {
System.out.print(ESCAPE + "[" + spaces + "B");
}
public static void moveLeft(int spaces) {
System.out.print(ESCAPE + "[" + spaces + "C");
}
public static void moveRight(int spaces) {
System.out.print(ESCAPE + "[" + spaces + "D");
}
public static void moveToColumn(int column) {
System.out.print(ESCAPE + "[" + column + "G");
}
public static void hideCursor() {
System.out.print(ESCAPE);
System.out.print("[?25l");
}
public static void reset() {
System.out.print(ESCAPE);
System.out.print("[?25h");
System.out.print(ESCAPE);
System.out.print("[0m");
}
public static void setColor(Color c) {
System.out.print(ESCAPE);
System.out.print("[");
switch (c) {
case BLACK: System.out.print("30");
break;
case RED: System.out.print("31");
break;
case GREEN: System.out.print("32");
break;
case YELLOW: System.out.print("33");
break;
case BLUE: System.out.print("34");
break;
case MAGENTA: System.out.print("35");
break;
case CYAN: System.out.print("36");
break;
case WHITE: System.out.print("37");
break;
}
System.out.print("m");
}
}