Index: sdk/lib/_internal/pub_generated/lib/src/progress.dart |
diff --git a/sdk/lib/_internal/pub_generated/lib/src/progress.dart b/sdk/lib/_internal/pub_generated/lib/src/progress.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3d2454bdfc3f8d1baec17482ce0ff575d18e8cad |
--- /dev/null |
+++ b/sdk/lib/_internal/pub_generated/lib/src/progress.dart |
@@ -0,0 +1,48 @@ |
+library pub.progress; |
+import 'dart:async'; |
+import 'dart:io'; |
+import 'log.dart' as log; |
+import 'utils.dart'; |
+class Progress { |
+ Timer _timer; |
+ final _stopwatch = new Stopwatch(); |
+ final String _message; |
+ String get _time => "(${niceDuration(_stopwatch.elapsed)})"; |
+ Progress(this._message, {bool fine: false}) { |
+ _stopwatch.start(); |
+ var level = fine ? log.Level.FINE : log.Level.MESSAGE; |
+ if (stdioType(stdout) != StdioType.TERMINAL || |
+ !log.verbosity.isLevelVisible(level) || |
+ log.json.enabled || |
+ fine || |
+ log.verbosity.isLevelVisible(log.Level.FINE)) { |
+ log.write(level, "$_message..."); |
+ return; |
+ } |
+ _update(); |
+ _timer = new Timer.periodic(new Duration(milliseconds: 100), (_) { |
+ _update(); |
+ }); |
+ } |
+ void stop() { |
+ _stopwatch.stop(); |
+ log.fine("$_message finished $_time."); |
+ if (_timer == null) return; |
+ _timer.cancel(); |
+ _timer = null; |
+ _update(); |
+ stdout.writeln(); |
+ } |
+ void stopAnimating() { |
+ if (_timer == null) return; |
+ stdout.writeln(log.format("\r$_message...")); |
+ _timer.cancel(); |
+ _timer = null; |
+ } |
+ void _update() { |
+ stdout.write(log.format("\r$_message... ")); |
+ if (_stopwatch.elapsed.inSeconds > 0) { |
+ stdout.write(log.gray(_time)); |
+ } |
+ } |
+} |