| 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 /// Helper functionality to make working with IO easier. | 5 /// Helper functionality to make working with IO easier. |
| 6 library io; | 6 library io; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 new ByteStream(stdin).toStringStream()); | 376 new ByteStream(stdin).toStringStream()); |
| 377 | 377 |
| 378 /// Displays a message and reads a yes/no confirmation from the user. Returns | 378 /// Displays a message and reads a yes/no confirmation from the user. Returns |
| 379 /// a [Future] that completes to `true` if the user confirms or `false` if they | 379 /// a [Future] that completes to `true` if the user confirms or `false` if they |
| 380 /// do not. | 380 /// do not. |
| 381 /// | 381 /// |
| 382 /// This will automatically append " (y/n)?" to the message, so [message] | 382 /// This will automatically append " (y/n)?" to the message, so [message] |
| 383 /// should just be a fragment like, "Are you sure you want to proceed". | 383 /// should just be a fragment like, "Are you sure you want to proceed". |
| 384 Future<bool> confirm(String message) { | 384 Future<bool> confirm(String message) { |
| 385 log.fine('Showing confirm message: $message'); | 385 log.fine('Showing confirm message: $message'); |
| 386 stdoutSink.add("$message (y/n)? ".charCodes); | 386 stdoutSink.add("$message (y/n)? ".codeUnits); |
| 387 return streamFirst(stdinLines) | 387 return streamFirst(stdinLines) |
| 388 .then((line) => new RegExp(r"^[yY]").hasMatch(line)); | 388 .then((line) => new RegExp(r"^[yY]").hasMatch(line)); |
| 389 } | 389 } |
| 390 | 390 |
| 391 /// Reads and discards all output from [stream]. Returns a [Future] that | 391 /// Reads and discards all output from [stream]. Returns a [Future] that |
| 392 /// completes when the stream is closed. | 392 /// completes when the stream is closed. |
| 393 Future drainStream(Stream stream) { | 393 Future drainStream(Stream stream) { |
| 394 return stream.reduce(null, (x, y) {}); | 394 return stream.reduce(null, (x, y) {}); |
| 395 } | 395 } |
| 396 | 396 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 804 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
| 805 | 805 |
| 806 bool get success => exitCode == 0; | 806 bool get success => exitCode == 0; |
| 807 } | 807 } |
| 808 | 808 |
| 809 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 809 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 810 Uri _getUri(uri) { | 810 Uri _getUri(uri) { |
| 811 if (uri is Uri) return uri; | 811 if (uri is Uri) return uri; |
| 812 return Uri.parse(uri); | 812 return Uri.parse(uri); |
| 813 } | 813 } |
| OLD | NEW |