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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 const int _STDIO_HANDLE_TYPE_TERMINAL = 0; | 7 const int _STDIO_HANDLE_TYPE_TERMINAL = 0; |
8 const int _STDIO_HANDLE_TYPE_PIPE = 1; | 8 const int _STDIO_HANDLE_TYPE_PIPE = 1; |
9 const int _STDIO_HANDLE_TYPE_FILE = 2; | 9 const int _STDIO_HANDLE_TYPE_FILE = 2; |
10 const int _STDIO_HANDLE_TYPE_SOCKET = 3; | 10 const int _STDIO_HANDLE_TYPE_SOCKET = 3; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 /** | 52 /** |
53 * Synchronously read a line from stdin. This call will block until a full | 53 * Synchronously read a line from stdin. This call will block until a full |
54 * line is available. The line will contain the newline character(s). | 54 * line is available. The line will contain the newline character(s). |
55 * | 55 * |
56 * If end-of-file is reached, `null` is returned. | 56 * If end-of-file is reached, `null` is returned. |
57 * | 57 * |
58 * If end-of-file is reached after some data has already been read, that data | 58 * If end-of-file is reached after some data has already been read, that data |
59 * is returned. | 59 * is returned. |
60 */ | 60 */ |
61 String readLineSync({Encoding encoding: Encoding.SYSTEM, | 61 String readLineSync({Encoding encoding: SYSTEM_ENCODING, |
62 bool retainNewlines: false}) { | 62 bool retainNewlines: false}) { |
63 const CR = 13; | 63 const CR = 13; |
64 const LF = 10; | 64 const LF = 10; |
65 var line = new StringBuffer(); | 65 var line = new StringBuffer(); |
66 bool end = false; | 66 bool end = false; |
67 bool lastCharWasCR = false; | 67 bool lastCharWasCR = false; |
68 var error; | 68 var error; |
69 | 69 |
70 StreamController<List<int>> controller = | 70 StreamController<List<int>> controller = |
71 new StreamController<List<int>>(sync: true); | 71 new StreamController<List<int>>(sync: true); |
72 Stream stream = controller.stream.transform(new StringDecoder(encoding)); | 72 Stream stream = controller.stream.transform(encoding.decoder); |
73 stream.listen((String str) { | 73 stream.listen((String str) { |
74 line.write(str); | 74 line.write(str); |
75 }, onError: (e) { | 75 }, onError: (e) { |
76 error = e; | 76 error = e; |
77 }, onDone: () { | 77 }, onDone: () { |
78 end = true; | 78 end = true; |
79 }); | 79 }); |
80 | 80 |
81 bool empty = true; | 81 bool empty = true; |
82 while (!end) { | 82 while (!end) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 247 } |
248 return StdioType.OTHER; | 248 return StdioType.OTHER; |
249 } | 249 } |
250 | 250 |
251 | 251 |
252 class _StdIOUtils { | 252 class _StdIOUtils { |
253 external static IOSink _getStdioOutputStream(int fd); | 253 external static IOSink _getStdioOutputStream(int fd); |
254 external static Stdin _getStdioInputStream(); | 254 external static Stdin _getStdioInputStream(); |
255 external static int _socketType(nativeSocket); | 255 external static int _socketType(nativeSocket); |
256 } | 256 } |
OLD | NEW |