-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnsiStylingTest.java
More file actions
95 lines (78 loc) · 3.54 KB
/
Copy pathAnsiStylingTest.java
File metadata and controls
95 lines (78 loc) · 3.54 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.util.Scanner;
public class AnsiStylingTest {
// ANSI codes for styling
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static final String WHITE = "\u001B[37m";
public static final String BG_BLUE = "\u001B[44m";
public static final String BG_GREEN = "\u001B[42m";
public static final String BOLD = "\u001B[1m";
public static final String UNDERLINE = "\u001B[4m";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean running = true;
while (running) {
// Clear screen and redraw
clearScreenWithBackground(BG_BLUE);
drawPersistentHeader();
System.out.print(GREEN + "\nEnter command (menu/exit): " + RESET);
String input = scanner.nextLine().trim().toLowerCase();
switch (input) {
case "menu":
showMenu();
break;
case "exit":
running = false;
break;
case "calculator":
System.out.println(YELLOW + "Calculator mode selected (not implemented)." + RESET);
break;
default:
System.out.println(RED + "Unknown command. Try again." + RESET);
}
}
System.out.println(RED + "Exiting the program. Goodbye!" + RESET);
}
private static void clearScreenWithBackground(String backgroundColor) {
System.out.print("\033[H\033[2J"); // Clear screen
System.out.flush();
// Simulate full background color
System.out.print(backgroundColor);
for (int i = 0; i < 50; i++) {
System.out.println(" ".repeat(80)); // Adjust width for your terminal
}
System.out.print(RESET); // Reset styling
}
private static void drawPersistentHeader() {
System.out.print("\033[0;0H"); // Move cursor to top-left
System.out.println(BG_GREEN + BOLD + WHITE + "***************************************");
System.out.println("* WELCOME TO CLI KALK *");
System.out.println("* (KALK v1.0) *");
System.out.println("***************************************" + RESET);
}
private static void showMenu() {
clearScreenWithBackground(BG_GREEN);
drawPersistentHeader();
System.out.println(YELLOW + "\nAvailable Features:" + RESET);
String[] headers = { "Feature", "Description" };
String[][] data = {
{ "Calculator", "Evaluate expressions" },
{ "Linear Algebra", "Perform matrix operations" },
{ "Differentiation", "Find derivatives" }
};
printTable(headers, data);
System.out.println("\n" + GREEN + "Enter your next command (calculator/exit):" + RESET);
}
private static void printTable(String[] headers, String[][] data) {
System.out.println(BOLD + WHITE + "+----------------+----------------+");
System.out.printf("| %-14s | %-14s |\n", headers[0], headers[1]);
System.out.println("+----------------+----------------+" + RESET);
for (String[] row : data) {
System.out.printf("| %-14s | %-14s |\n", row[0], row[1]);
}
System.out.println(WHITE + "+----------------+----------------+" + RESET);
}
}