mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Show colorized error messages
This commit is contained in:
@@ -161,7 +161,7 @@
|
||||
};
|
||||
|
||||
compileScript = function(file, input, base) {
|
||||
var message, o, options, t, task;
|
||||
var message, o, options, t, task, useColors;
|
||||
o = opts;
|
||||
options = compileOptions(file);
|
||||
try {
|
||||
@@ -196,7 +196,7 @@
|
||||
if (CoffeeScript.listeners('failure').length) {
|
||||
return;
|
||||
}
|
||||
message = err instanceof CompilerError ? err.prettyMessage(file || '[stdin]', input) : err.stack || ("ERROR: " + err);
|
||||
message = err instanceof CompilerError ? (useColors = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS, err.prettyMessage(file || '[stdin]', input, useColors)) : err.stack || ("ERROR: " + err);
|
||||
if (o.watch) {
|
||||
if (o.watch) {
|
||||
return printLine(message + '\x07');
|
||||
|
||||
@@ -29,12 +29,19 @@
|
||||
return new CompilerError(message, first_line, first_column, last_line, last_column);
|
||||
};
|
||||
|
||||
CompilerError.prototype.prettyMessage = function(fileName, code) {
|
||||
var end, errorLine, marker, message, start;
|
||||
CompilerError.prototype.prettyMessage = function(fileName, code, useColors) {
|
||||
var colorize, end, errorLine, marker, message, start;
|
||||
errorLine = code.split('\n')[this.startLine];
|
||||
start = this.startColumn;
|
||||
end = this.startLine === this.endLine ? this.endColumn : errorLine.length - 1;
|
||||
marker = repeat(' ', start) + repeat('^', end - start + 1);
|
||||
end = this.startLine === this.endLine ? this.endColumn + 1 : errorLine.length;
|
||||
marker = repeat(' ', start) + repeat('^', end - start);
|
||||
if (useColors) {
|
||||
colorize = function(str) {
|
||||
return "\x1B[1;31m" + str + "\x1B[0m";
|
||||
};
|
||||
errorLine = errorLine.slice(0, start) + colorize(errorLine.slice(start, end)) + errorLine.slice(end);
|
||||
marker = colorize(marker);
|
||||
}
|
||||
message = "" + fileName + ":" + (this.startLine + 1) + ":" + (this.startColumn + 1) + ": error: " + this.message + "\n" + errorLine + "\n" + marker;
|
||||
return message;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user