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

Unified Diff: sdk/lib/_internal/pub_generated/lib/src/ascii_tree.dart

Issue 557563002: Store the async-await compiled pub code directly in the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months 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
Index: sdk/lib/_internal/pub_generated/lib/src/ascii_tree.dart
diff --git a/sdk/lib/_internal/pub_generated/lib/src/ascii_tree.dart b/sdk/lib/_internal/pub_generated/lib/src/ascii_tree.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b54a4b765ad59fe86b8c0183ccf3fd86a01694fd
--- /dev/null
+++ b/sdk/lib/_internal/pub_generated/lib/src/ascii_tree.dart
@@ -0,0 +1,69 @@
+library pub.ascii_tree;
+import 'package:path/path.dart' as path;
+import 'log.dart' as log;
+import 'utils.dart';
+String fromFiles(List<String> files, {String baseDir, bool showAllChildren}) {
+ var root = {};
+ for (var file in files) {
+ if (baseDir != null) file = path.relative(file, from: baseDir);
+ var parts = path.split(file);
+ var directory = root;
+ for (var part in path.split(file)) {
+ directory = directory.putIfAbsent(part, () => {});
+ }
+ }
+ return fromMap(root, showAllChildren: showAllChildren);
+}
+String fromMap(Map map, {bool showAllChildren}) {
+ var buffer = new StringBuffer();
+ _draw(buffer, "", null, map, showAllChildren: showAllChildren);
+ return buffer.toString();
+}
+void _drawLine(StringBuffer buffer, String prefix, bool isLastChild,
+ String name) {
+ buffer.write(prefix);
+ if (name != null) {
+ if (isLastChild) {
+ buffer.write(log.gray("'-- "));
+ } else {
+ buffer.write(log.gray("|-- "));
+ }
+ }
+ buffer.writeln(name);
+}
+String _getPrefix(bool isRoot, bool isLast) {
+ if (isRoot) return "";
+ if (isLast) return " ";
+ return log.gray("| ");
+}
+void _draw(StringBuffer buffer, String prefix, String name, Map children,
+ {bool showAllChildren, bool isLast: false}) {
+ if (showAllChildren == null) showAllChildren = false;
+ if (name != null) _drawLine(buffer, prefix, isLast, name);
+ var childNames = ordered(children.keys);
+ drawChild(bool isLastChild, String child) {
+ var childPrefix = _getPrefix(name == null, isLast);
+ _draw(
+ buffer,
+ '$prefix$childPrefix',
+ child,
+ children[child],
+ showAllChildren: showAllChildren,
+ isLast: isLastChild);
+ }
+ if (name == null || showAllChildren || childNames.length <= 10) {
+ for (var i = 0; i < childNames.length; i++) {
+ drawChild(i == childNames.length - 1, childNames[i]);
+ }
+ } else {
+ drawChild(false, childNames[0]);
+ drawChild(false, childNames[1]);
+ drawChild(false, childNames[2]);
+ buffer.write(prefix);
+ buffer.write(_getPrefix(name == null, isLast));
+ buffer.writeln(log.gray('| (${childNames.length - 6} more...)'));
+ drawChild(false, childNames[childNames.length - 3]);
+ drawChild(false, childNames[childNames.length - 2]);
+ drawChild(true, childNames[childNames.length - 1]);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698