Skip to content

Commit

Permalink
Coloring console output
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Jan 11, 2024
1 parent 7e224ca commit c4687d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
* See {@link MMAConsole}
*/
public class Console {

private final static String RESET = "\u001B[0m";
private final static String GREEN = "\033[0;32m";
private final static String RED = "\033[0;31m";
private final static String BLUE = "\033[0;34m";

/** No timeout limit as the default value for Symja expression evaluation. */
private long fSeconds = -1;

Expand Down Expand Up @@ -123,7 +129,7 @@ public static void main(final String args[]) {

while (true) {
try {
String inputExpression = console.readString(stdout, ">> ");
String inputExpression = console.readString(stdout, "\n" + BLUE + ">> " + RESET);
if (inputExpression != null) {
trimmedInput = inputExpression.trim();
if (inputExpression.length() > 1
Expand Down Expand Up @@ -200,7 +206,7 @@ public static void main(final String args[]) {
stderr.println("Automatically closing brackets: " + postfix);
trimmedInput = trimmedInput + postfix;
}
stdout.println("In[" + COUNTER + "]:= " + trimmedInput);
stdout.println(GREEN + "In[" + COUNTER + "]:= " + RESET + trimmedInput);
stdout.flush();
// if (console.fPrettyPrinter) {
// console.prettyPrinter(inputExpression);
Expand All @@ -222,7 +228,7 @@ public static void main(final String args[]) {
private String resultPrinter(String inputExpression) {
String outputExpression = interpreter(inputExpression);
if (outputExpression.length() > 0) {
stdout.print("Out[" + COUNTER + "]= ");
stdout.print(RED + "Out[" + COUNTER + "]= " + RESET);
stdout.flush();
stdout.println(Errors.shorten(outputExpression, 1000));
stdout.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
* See {@link Console}
*/
public class MMAConsole {

private final static String RESET = "\u001B[0m";
private final static String GREEN = "\033[0;32m";
private final static String RED = "\033[0;31m";
private final static String BLUE = "\033[0;34m";

/** No timeout limit as the default value for Symja expression evaluation. */
private long fSeconds = -1;

Expand Down Expand Up @@ -127,7 +133,7 @@ public static void main(final String args[]) {

while (true) {
try {
String inputExpression = console.readString(stdout, ">> ");
String inputExpression = console.readString(stdout, "\n" + BLUE + ">> " + RESET);
if (inputExpression != null) {
trimmedInput = inputExpression.trim();
if (inputExpression.length() > 1
Expand Down Expand Up @@ -186,7 +192,7 @@ public static void main(final String args[]) {
stderr.println("Automatically closing brackets: " + postfix);
trimmedInput = trimmedInput + postfix;
}
stdout.println("In[" + COUNTER + "]:= " + trimmedInput);
stdout.println(GREEN + "In[" + COUNTER + "]:= " + RESET + trimmedInput);
stdout.flush();
// if (outputExpression.length() > 0) {
// stdout.println("Out[" + COUNTER + "]: " + outputExpression);
Expand All @@ -208,10 +214,11 @@ public static void main(final String args[]) {
}
}


private String resultPrinter(String inputExpression) {
String outputExpression = interpreter(inputExpression);
if (outputExpression.length() > 0) {
stdout.print("Out[" + COUNTER + "]= ");
stdout.print(RED + "Out[" + COUNTER + "]= " + RESET);
stdout.flush();
stdout.println(Errors.shorten(outputExpression, 1000));
stdout.flush();
Expand Down

0 comments on commit c4687d1

Please sign in to comment.