OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Internal debugging utilities. | 5 /// Internal debugging utilities. |
6 library dart_style.src.debug; | 6 library dart_style.src.debug; |
7 | 7 |
8 import 'chunk.dart'; | 8 import 'chunk.dart'; |
9 import 'line_prefix.dart'; | 9 import 'line_prefix.dart'; |
10 import 'line_splitter.dart'; | 10 import 'line_splitter.dart'; |
11 | 11 |
12 /// Set this to `true` to turn out diagnostic output while formatting. | 12 /// Set this to `true` to turn out diagnostic output while formatting. |
13 bool debugFormatter = false; | 13 bool debugFormatter = false; |
14 | 14 |
15 bool useAnsiColors = false; | 15 bool useAnsiColors = false; |
16 | 16 |
17 const UNICODE_SECT = "\u00a7"; | 17 const unicodeSection = "\u00a7"; |
18 const UNICODE_MIDDOT = "\u00b7"; | 18 const unicodeMidDot = "\u00b7"; |
19 const UNICODE_LASQUO = "\u2039"; | |
20 const UNICODE_RASQUO = "\u203a"; | |
21 | 19 |
22 /// Constants for ANSI color escape codes. | 20 /// Constants for ANSI color escape codes. |
23 class Color { | 21 class Color { |
24 static final cyan = _color("\u001b[36m"); | 22 static final cyan = _color("\u001b[36m"); |
25 static final gray = _color("\u001b[1;30m"); | 23 static final gray = _color("\u001b[1;30m"); |
26 static final green = _color("\u001b[32m"); | 24 static final green = _color("\u001b[32m"); |
27 static final red = _color("\u001b[31m"); | 25 static final red = _color("\u001b[31m"); |
28 static final magenta = _color("\u001b[35m"); | 26 static final magenta = _color("\u001b[35m"); |
29 static final none = _color("\u001b[0m"); | 27 static final none = _color("\u001b[0m"); |
30 static final noColor = _color("\u001b[39m"); | 28 static final noColor = _color("\u001b[39m"); |
(...skipping 23 matching lines...) Expand all Loading... |
54 ..write(Color.none); | 52 ..write(Color.none); |
55 | 53 |
56 for (var i = prefix.length; i < chunks.length; i++) { | 54 for (var i = prefix.length; i < chunks.length; i++) { |
57 var chunk = chunks[i]; | 55 var chunk = chunks[i]; |
58 | 56 |
59 buffer.write(chunk.text); | 57 buffer.write(chunk.text); |
60 | 58 |
61 if (chunk.isSoftSplit) { | 59 if (chunk.isSoftSplit) { |
62 var color = splits.contains(chunk.param) ? Color.green : Color.gray; | 60 var color = splits.contains(chunk.param) ? Color.green : Color.gray; |
63 | 61 |
64 buffer.write("$color$UNICODE_SECT${chunk.param.cost}"); | 62 buffer.write("$color$unicodeSection${chunk.param.cost}"); |
65 if (chunk.nesting != -1) buffer.write(":${chunk.nesting}"); | 63 if (chunk.nesting != -1) buffer.write(":${chunk.nesting}"); |
66 buffer.write("${Color.none}"); | 64 buffer.write("${Color.none}"); |
67 } else if (chunk.isHardSplit) { | 65 } else if (chunk.isHardSplit) { |
68 buffer.write("${Color.magenta}\\n${"->" * chunk.indent}${Color.none}"); | 66 buffer.write("${Color.magenta}\\n${"->" * chunk.indent}${Color.none}"); |
69 } | 67 } |
70 } | 68 } |
71 | 69 |
72 print(buffer); | 70 print(buffer); |
73 } | 71 } |
74 | 72 |
(...skipping 20 matching lines...) Expand all Loading... |
95 buffer.writeln(); | 93 buffer.writeln(); |
96 | 94 |
97 indent = chunk.indent + splits.getNesting(i); | 95 indent = chunk.indent + splits.getNesting(i); |
98 buffer | 96 buffer |
99 ..write(Color.gray) | 97 ..write(Color.gray) |
100 ..write("| " * indent) | 98 ..write("| " * indent) |
101 ..write(Color.none); | 99 ..write(Color.none); |
102 } | 100 } |
103 | 101 |
104 // Should have a valid set of splits when we get here. | 102 // Should have a valid set of splits when we get here. |
105 assert(indent != INVALID_SPLITS); | 103 assert(indent != invalidSplits); |
106 } else { | 104 } else { |
107 if (chunk.spaceWhenUnsplit) buffer.write(" "); | 105 if (chunk.spaceWhenUnsplit) buffer.write(" "); |
108 } | 106 } |
109 } | 107 } |
110 | 108 |
111 buffer.write(chunks.last.text); | 109 buffer.write(chunks.last.text); |
112 print(buffer); | 110 print(buffer); |
113 } | 111 } |
114 | 112 |
115 String _color(String ansiEscape) => useAnsiColors ? ansiEscape : ""; | 113 String _color(String ansiEscape) => useAnsiColors ? ansiEscape : ""; |
OLD | NEW |