-
Notifications
You must be signed in to change notification settings - Fork 30
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
Colorizing terminal output #224
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I like it pretty :)
Could you please have a look at the comments?
I am also wondering whether this needs to have a flag to disable it, some java property.
When we might run in an environment without ansi term support, this might cause issues.
I checked whether that can be automatically detected, but that seems to be rather problematic.
core-lib/System.ns
Outdated
@@ -25,7 +25,8 @@ class System usingVmMirror: vmMirror = Value ( | |||
(* Exiting *) | |||
public exit: error = ( vmMirror exit: error ) | |||
public exit = ( self exit: 0 ) | |||
public error: msg = ( self printNewline: 'ERROR: ' + msg. self exit: 1 ) | |||
public warning: msg = ( vmMirror printWarning: msg. ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one space too much for alignment before =
?
src/som/VM.java
Outdated
@@ -315,17 +315,43 @@ public void errorExit(final String message) { | |||
requestExit(1); | |||
} | |||
|
|||
private static class AnsiColor8 { | |||
private static String black = "\u001b[30m"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason why these are not final?
and, if they should be final, could we capitalize the names, e.g., BLACK
to indicate them as constants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also getting unwieldily here.
Could you move all printing into something like an Output
or Terminal
class?
The som
package is probably the right place for it.
Hi Stefan, I've updated the changes to include a new argument, added to the I've also changed the fields of the |
som
Outdated
@@ -105,7 +105,8 @@ parser.add_argument('-T', '--no-trace', help='do not print truffle compilation i | |||
parser.add_argument('--no-graph-pe', help='disable Graph PE', | |||
dest='graph_pe', action='store_false', default=True) | |||
|
|||
|
|||
parser.add_argument('-O', '--no-ansi', help='Turns off ANSI coloring for output from interperter', | |||
dest='no_ansi_coloring', action='store_true', default=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid negation where possible.
So, dest='ansi_coloring', action='store_false', default=True
. This is much more explicit and easier to read.
som
Outdated
@@ -224,6 +228,8 @@ if not args.interpreter and args.igv_to_file: | |||
flags += ['-Dgraal.PrintIdealGraphFile=true'] | |||
if args.igv_methods: | |||
flags += ['-Dsom.igvDumpAfterParsing=true'] | |||
if args.no_ansi_coloring: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there two flags added?
-Dsom.noAnsiColoring=true
and -Dsom.useANSIColor=false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, missed this during clean-up.
src/som/Output.java
Outdated
import som.vm.VmSettings; | ||
|
||
|
||
public class Output { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a brief comment.
src/som/Output.java
Outdated
/** | ||
* This method is used to print reports about the number of created artifacts. | ||
* For example actors, messages and promises. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please first the comment, then the annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there should be a linter rule for that...
src/som/Output.java
Outdated
public static void print(final String msg, final String color) { | ||
// Checkstyle: stop | ||
if (VmSettings.NO_ANSI_COLOR_IN_OUTPUT) { | ||
System.out.print(msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a correct patch.
We used to output to System.err
when showing errors.
src/som/vm/VmSettings.java
Outdated
@@ -29,6 +29,8 @@ | |||
|
|||
public static final boolean IGV_DUMP_AFTER_PARSING; | |||
|
|||
public static final boolean NO_ANSI_COLOR_IN_OUTPUT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No negation, please!
And, I can't see the logs currently because of Travis issues, but I am pretty sure they are failing. |
Hmm, it seems the Eclipse Console has ANSI support now (or perhaps I turned it off somewhere). Maybe the flag should be to turn the coloring on rather than off? |
Say what? I don't understand, but this doesn't make sense to me. |
Sorry, I had meant to say that Eclipse console does not have support for it. |
- move all output related code into Output class - colorize print, warning, and error methods - output errors to stderr - add som.useAnsiColoring flag to control use of colors - in launcher, determine use of colors based on whether it looks like a terminal Co-authored-by: Stefan Marr <[email protected]> Signed-off-by: Stefan Marr <[email protected]>
Since this is a conceptually pretty simple change, I did condense the history. |
These changes enabled messages printed to standard out to be colorized when they are either a warning or an error.
I've moved all print methods (that were previously in
VM.java
) into a newOutput.java
module. The module contains print, warning, and error methods that are called whenever SOMns prints something to standard output or standard error. Each method uses the staticAnsiColor8
class to prefix their messages with the corresponding ANSI color code: red for errors, yellow for warnings, and no coloring for regular messages.To provide access to the printing methods from Newspeak, I've added a pair of new System primitives:
PrintWarningPrim
andPrintErrorPim
. These can be invoked, via the System module.Finally, the ANSI coloring is turned off by default (since it's not supported by Eclipse's Console widget). The argument
--ansi-coloring
, or the shorter version-ac
, can be added when invoking SOMns from the command line to turn the ANSI coloring on.