Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1128)

Unified Diff: frog/source.dart

Issue 8823010: frog: life is better with colors :) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « frog/minfrog.dart ('k') | frog/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/source.dart
diff --git a/frog/source.dart b/frog/source.dart
index ab62a2fe3a43592c14adba3e54dc23484e70d16c..beddb424672867115e5c04f959a2edc564271eb3 100644
--- a/frog/source.dart
+++ b/frog/source.dart
@@ -72,7 +72,8 @@ class SourceFile implements Comparable {
* Create a pretty string representation from a character position
* in the file.
*/
- String getLocationMessage(String message, int start, [int end, bool includeText=false]) {
+ String getLocationMessage(String message, int start,
+ [int end, bool includeText=false]) {
var line = getLine(start);
var column = getColumn(line, start);
@@ -87,17 +88,28 @@ class SourceFile implements Comparable {
} else {
textLine = text.substring(_lineStarts[line]) + '\n';
}
- buf.add(textLine);
+
+ int toColumn = Math.min(column + (end-start), textLine.length);
+ if (options.useColors) {
+ buf.add(textLine.substring(0, column));
+ buf.add(_RED_COLOR);
+ buf.add(textLine.substring(column, toColumn));
+ buf.add(_NO_COLOR);
+ buf.add(textLine.substring(toColumn));
+ } else {
+ buf.add(textLine);
+ }
+
int i = 0;
for (; i < column; i++) {
buf.add(' ');
}
- int toColumn = Math.min(column + (end-start), textLine.length);
-
+ if (options.useColors) buf.add(_RED_COLOR);
for (; i < toColumn; i++) {
buf.add('^');
}
+ if (options.useColors) buf.add(_NO_COLOR);
}
return buf.toString();
@@ -138,7 +150,7 @@ class SourceSpan implements Comparable {
}
toMessageString(String message) {
- return file.getLocationMessage(message, start, end, true);
+ return file.getLocationMessage(message, start, end: end, includeText: true);
}
String get locationText() {
« no previous file with comments | « frog/minfrog.dart ('k') | frog/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698