| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Helper functionality to make working with IO easier. | 5 /// Helper functionality to make working with IO easier. |
| 6 library pub.io; | 6 library pub.io; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 import 'dart:convert'; | 10 import 'dart:convert'; |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 | 557 |
| 558 /// Displays a message and reads a yes/no confirmation from the user. | 558 /// Displays a message and reads a yes/no confirmation from the user. |
| 559 /// | 559 /// |
| 560 /// Returns a [Future] that completes to `true` if the user confirms or `false` | 560 /// Returns a [Future] that completes to `true` if the user confirms or `false` |
| 561 /// if they do not. | 561 /// if they do not. |
| 562 /// | 562 /// |
| 563 /// This will automatically append " (y/n)?" to the message, so [message] | 563 /// This will automatically append " (y/n)?" to the message, so [message] |
| 564 /// should just be a fragment like, "Are you sure you want to proceed". | 564 /// should just be a fragment like, "Are you sure you want to proceed". |
| 565 Future<bool> confirm(String message) { | 565 Future<bool> confirm(String message) { |
| 566 log.fine('Showing confirm message: $message'); | 566 log.fine('Showing confirm message: $message'); |
| 567 if (runningAsTest) { | 567 if (runningFromTest) { |
| 568 log.message("$message (y/n)?"); | 568 log.message("$message (y/n)?"); |
| 569 } else { | 569 } else { |
| 570 stdout.write(log.format("$message (y/n)? ")); | 570 stdout.write(log.format("$message (y/n)? ")); |
| 571 } | 571 } |
| 572 return streamFirst(stdinLines) | 572 return streamFirst(stdinLines) |
| 573 .then((line) => new RegExp(r"^[yY]").hasMatch(line)); | 573 .then((line) => new RegExp(r"^[yY]").hasMatch(line)); |
| 574 } | 574 } |
| 575 | 575 |
| 576 /// Reads and discards all output from [stream]. | 576 /// Reads and discards all output from [stream]. |
| 577 /// | 577 /// |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 | 1052 |
| 1053 // TODO(rnystrom): Remove this and change to returning one string. | 1053 // TODO(rnystrom): Remove this and change to returning one string. |
| 1054 static List<String> _toLines(String output) { | 1054 static List<String> _toLines(String output) { |
| 1055 var lines = splitLines(output); | 1055 var lines = splitLines(output); |
| 1056 if (!lines.isEmpty && lines.last == "") lines.removeLast(); | 1056 if (!lines.isEmpty && lines.last == "") lines.removeLast(); |
| 1057 return lines; | 1057 return lines; |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 bool get success => exitCode == exit_codes.SUCCESS; | 1060 bool get success => exitCode == exit_codes.SUCCESS; |
| 1061 } | 1061 } |
| OLD | NEW |