OLD | NEW |
---|---|
1 import 'package:dart_style/dart_style.dart'; | 1 import 'package:dart_style/dart_style.dart'; |
2 | 2 |
3 import 'package:dart_style/src/debug.dart'; | 3 import 'package:dart_style/src/debug.dart'; |
4 | 4 |
5 void main(List<String> args) { | 5 void main(List<String> args) { |
6 // Enable debugging so you can see some of the formatter's internal state. | 6 // Enable debugging so you can see some of the formatter's internal state. |
7 // Normal users do not do this. | 7 // Normal users do not do this. |
8 debugFormatter = true; | 8 debugFormatter = true; |
9 useAnsiColors = true; | 9 useAnsiColors = true; |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... | |
25 var formatter = new DartFormatter(pageWidth: pageWidth); | 25 var formatter = new DartFormatter(pageWidth: pageWidth); |
26 | 26 |
27 var result; | 27 var result; |
28 if (isCompilationUnit) { | 28 if (isCompilationUnit) { |
29 result = formatter.format(source); | 29 result = formatter.format(source); |
30 } else { | 30 } else { |
31 result = formatter.formatStatement(source); | 31 result = formatter.formatStatement(source); |
32 } | 32 } |
33 | 33 |
34 if (useAnsiColors) { | 34 if (useAnsiColors) { |
35 result = result.replaceAll(" ", "\u001b[1;30m·\u001b[0m"); | 35 result = result.replaceAll( |
36 " ", "${Color.gray}$unicodeMidDot${Color.none}"); | |
pquitslund
2015/01/06 19:36:25
Nice.
| |
36 } | 37 } |
37 | 38 |
38 drawRuler("before", pageWidth); | 39 drawRuler("before", pageWidth); |
39 print(source); | 40 print(source); |
40 drawRuler("after", pageWidth); | 41 drawRuler("after", pageWidth); |
41 print(result); | 42 print(result); |
42 } on FormatterException catch (error) { | 43 } on FormatterException catch (error) { |
43 print(error.message()); | 44 print(error.message()); |
44 } | 45 } |
45 } | 46 } |
46 | 47 |
47 void drawRuler(String label, int width) { | 48 void drawRuler(String label, int width) { |
48 var padding = " " * (width - label.length - 1); | 49 var padding = " " * (width - label.length - 1); |
49 print("$label:$padding|"); | 50 print("$label:$padding|"); |
50 } | 51 } |
OLD | NEW |