Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added support for ANSI Colours in Drifty CLI #329

Merged
merged 17 commits into from
Nov 8, 2023
Merged
36 changes: 25 additions & 11 deletions src/main/java/Utils/MessageBroker.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ public void msgStyleInfo(String message) {

private void sendMessage(String message, MessageType messageType, MessageCategory messageCategory) {
if (Mode.isCLI()) {
switch (messageType) {
case INFO:
message = "\033[92m" + message + "\033[0m";
break;
case ERROR:
message = "\033[91m" + message + "\033[0m";
break;
case WARN:
message = "\033[93m" + message + "\033[0m";
break;
default:
output.println(message);
break;
}
if (!messageCategory.equals(LOG)) {
output.println(message);
}
Expand All @@ -102,21 +116,21 @@ private void sendMessage(String message, MessageType messageType, MessageCategor
ui = null;
}
Color color = switch (messageType) {
case ERROR -> RED;
case INFO -> GREEN;
default -> YELLOW;
case ERROR -> RED;
case INFO -> GREEN;
default -> YELLOW;
};
switch (messageCategory) {
case LINK -> ui.setLinkOutput(color, message);
case FILENAME -> ui.setFilenameOutput(color, message);
case DIRECTORY -> ui.setDirOutput(color, message);
case DOWNLOAD -> ui.setDownloadOutput(color, message);
default -> {
if (!message.isEmpty()) {
logger.log(messageType, message);
}
case LINK -> ui.setLinkOutput(color, message);
case FILENAME -> ui.setFilenameOutput(color, message);
case DIRECTORY -> ui.setDirOutput(color, message);
case DOWNLOAD -> ui.setDownloadOutput(color, message);
default -> {
if (!message.isEmpty()) {
logger.log(messageType, message);
}
}
}
}
}
}
Loading