| 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 'log.dart' as log; | 8 import 'log.dart' as log; |
| 9 import 'path.dart' as path; | 9 import 'path.dart' as path; |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 /// | |-- main.dart | 43 /// | |-- main.dart |
| 44 /// | '-- web copy | 44 /// | '-- web copy |
| 45 /// | '-- web_example.dart | 45 /// | '-- web_example.dart |
| 46 /// |-- lib | 46 /// |-- lib |
| 47 /// | '-- path.dart | 47 /// | '-- path.dart |
| 48 /// |-- pubspec.yaml | 48 /// |-- pubspec.yaml |
| 49 /// '-- test | 49 /// '-- test |
| 50 /// |-- absolute_test.dart | 50 /// |-- absolute_test.dart |
| 51 /// |-- all_test.dart | 51 /// |-- all_test.dart |
| 52 /// |-- basename_test.dart | 52 /// |-- basename_test.dart |
| 53 /// | (7 more...) | 53 /// | (7 more...) |
| 54 /// |-- path_windows_test.dart | 54 /// |-- path_windows_test.dart |
| 55 /// |-- relative_test.dart | 55 /// |-- relative_test.dart |
| 56 /// '-- split_test.dart | 56 /// '-- split_test.dart |
| 57 /// | 57 /// |
| 58 String generateTree(List<String> files) { | 58 String generateTree(List<String> files) { |
| 59 // Parse out the files into a tree of nested maps. | 59 // Parse out the files into a tree of nested maps. |
| 60 var root = {}; | 60 var root = {}; |
| 61 for (var file in files) { | 61 for (var file in files) { |
| 62 var parts = path.split(file); | 62 var parts = path.split(file); |
| 63 var directory = root; | 63 var directory = root; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 // Recurse to the children. | 103 // Recurse to the children. |
| 104 var childNames = new List.from(children.keys); | 104 var childNames = new List.from(children.keys); |
| 105 childNames.sort(); | 105 childNames.sort(); |
| 106 | 106 |
| 107 _drawChild(bool isLastChild, String child) { | 107 _drawChild(bool isLastChild, String child) { |
| 108 var childPrefix = _getPrefix(name == null, isLast); | 108 var childPrefix = _getPrefix(name == null, isLast); |
| 109 _draw(buffer, '$prefix$childPrefix', isLastChild, child, children[child]); | 109 _draw(buffer, '$prefix$childPrefix', isLastChild, child, children[child]); |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (childNames.length <= 10) { | 112 if (name == null || childNames.length <= 10) { |
| 113 // Not too many, so show all the children. | 113 // Not too many, so show all the children. |
| 114 for (var i = 0; i < childNames.length; i++) { | 114 for (var i = 0; i < childNames.length; i++) { |
| 115 _drawChild(i == childNames.length - 1, childNames[i]); | 115 _drawChild(i == childNames.length - 1, childNames[i]); |
| 116 } | 116 } |
| 117 } else { | 117 } else { |
| 118 // Show the first few. | 118 // Show the first few. |
| 119 _drawChild(false, childNames[0]); | 119 _drawChild(false, childNames[0]); |
| 120 _drawChild(false, childNames[1]); | 120 _drawChild(false, childNames[1]); |
| 121 _drawChild(false, childNames[2]); | 121 _drawChild(false, childNames[2]); |
| 122 | 122 |
| 123 // Elide the middle ones. | 123 // Elide the middle ones. |
| 124 buffer.add(prefix); | 124 buffer.add(prefix); |
| 125 buffer.add(_getPrefix(name == null, isLast)); | 125 buffer.add(_getPrefix(name == null, isLast)); |
| 126 buffer.add('| (${childNames.length - 6} more...)\n'); | 126 buffer.add('| (${childNames.length - 6} more...)\n'); |
| 127 | 127 |
| 128 // Show the last few. | 128 // Show the last few. |
| 129 _drawChild(false, childNames[childNames.length - 3]); | 129 _drawChild(false, childNames[childNames.length - 3]); |
| 130 _drawChild(false, childNames[childNames.length - 2]); | 130 _drawChild(false, childNames[childNames.length - 2]); |
| 131 _drawChild(true, childNames[childNames.length - 1]); | 131 _drawChild(true, childNames[childNames.length - 1]); |
| 132 } | 132 } |
| 133 } | 133 } |
| OLD | NEW |