| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /// A simple library for rendering a list of files as a directory tree. | 5 /// A simple library for rendering a list of files as a directory tree. |
| 6 library directory_tree; | 6 library directory_tree; |
| 7 | 7 |
| 8 import '../../pkg/pathos/lib/path.dart' as path; | 8 import '../../pkg/pathos/lib/path.dart' as path; |
| 9 import 'log.dart' as log; | 9 import 'log.dart' as log; |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 // Walk the map recursively and render to a string. | 69 // Walk the map recursively and render to a string. |
| 70 var buffer = new StringBuffer(); | 70 var buffer = new StringBuffer(); |
| 71 _draw(buffer, '', false, null, root); | 71 _draw(buffer, '', false, null, root); |
| 72 return buffer.toString(); | 72 return buffer.toString(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void _drawLine(StringBuffer buffer, String prefix, bool isLastChild, | 75 void _drawLine(StringBuffer buffer, String prefix, bool isLastChild, |
| 76 String name) { | 76 String name) { |
| 77 // Print lines. | 77 // Print lines. |
| 78 buffer.add(prefix); | 78 buffer.write(prefix); |
| 79 if (name != null) { | 79 if (name != null) { |
| 80 if (isLastChild) { | 80 if (isLastChild) { |
| 81 buffer.add("'-- "); | 81 buffer.write("'-- "); |
| 82 } else { | 82 } else { |
| 83 buffer.add("|-- "); | 83 buffer.write("|-- "); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Print name. | 87 // Print name. |
| 88 buffer.add(name); | 88 buffer.writeln(name); |
| 89 buffer.add('\n'); | |
| 90 } | 89 } |
| 91 | 90 |
| 92 String _getPrefix(bool isRoot, bool isLast) { | 91 String _getPrefix(bool isRoot, bool isLast) { |
| 93 if (isRoot) return ""; | 92 if (isRoot) return ""; |
| 94 if (isLast) return " "; | 93 if (isLast) return " "; |
| 95 return "| "; | 94 return "| "; |
| 96 } | 95 } |
| 97 | 96 |
| 98 void _draw(StringBuffer buffer, String prefix, bool isLast, | 97 void _draw(StringBuffer buffer, String prefix, bool isLast, |
| 99 String name, Map children) { | 98 String name, Map children) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 114 for (var i = 0; i < childNames.length; i++) { | 113 for (var i = 0; i < childNames.length; i++) { |
| 115 _drawChild(i == childNames.length - 1, childNames[i]); | 114 _drawChild(i == childNames.length - 1, childNames[i]); |
| 116 } | 115 } |
| 117 } else { | 116 } else { |
| 118 // Show the first few. | 117 // Show the first few. |
| 119 _drawChild(false, childNames[0]); | 118 _drawChild(false, childNames[0]); |
| 120 _drawChild(false, childNames[1]); | 119 _drawChild(false, childNames[1]); |
| 121 _drawChild(false, childNames[2]); | 120 _drawChild(false, childNames[2]); |
| 122 | 121 |
| 123 // Elide the middle ones. | 122 // Elide the middle ones. |
| 124 buffer.add(prefix); | 123 buffer.write(prefix); |
| 125 buffer.add(_getPrefix(name == null, isLast)); | 124 buffer.write(_getPrefix(name == null, isLast)); |
| 126 buffer.add('| (${childNames.length - 6} more...)\n'); | 125 buffer.writeln('| (${childNames.length - 6} more...)'); |
| 127 | 126 |
| 128 // Show the last few. | 127 // Show the last few. |
| 129 _drawChild(false, childNames[childNames.length - 3]); | 128 _drawChild(false, childNames[childNames.length - 3]); |
| 130 _drawChild(false, childNames[childNames.length - 2]); | 129 _drawChild(false, childNames[childNames.length - 2]); |
| 131 _drawChild(true, childNames[childNames.length - 1]); | 130 _drawChild(true, childNames[childNames.length - 1]); |
| 132 } | 131 } |
| 133 } | 132 } |
| OLD | NEW |