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

Side by Side Diff: sdk/lib/io/stdio.dart

Issue 2698813002: [dart:io][windows] Make unicode characters display correctly. (Closed)
Patch Set: Address comments Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | tests/standalone/io/console_unicode_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 * the output is written. 159 * the output is written.
160 * 160 *
161 * In some situations this blocking behavior is undesirable as it does not 161 * In some situations this blocking behavior is undesirable as it does not
162 * provide the same non-blocking behavior as dart:io in general exposes. 162 * provide the same non-blocking behavior as dart:io in general exposes.
163 * Use the property [nonBlocking] to get an `IOSink` which has the non-blocking 163 * Use the property [nonBlocking] to get an `IOSink` which has the non-blocking
164 * behavior. 164 * behavior.
165 * 165 *
166 * This class can also be used to check whether `stdout` or `stderr` is 166 * This class can also be used to check whether `stdout` or `stderr` is
167 * connected to a terminal and query some terminal properties. 167 * connected to a terminal and query some terminal properties.
168 */ 168 */
169 class Stdout extends _StdSink implements IOSink { 169 class Stdout extends _StdFileSink implements IOSink {
170 final int _fd; 170 final int _fd;
171 IOSink _nonBlocking; 171 IOSink _nonBlocking;
172 172
173 Stdout._(IOSink sink, this._fd) : super(sink); 173 Stdout._(IOSink sink, this._fd) : super(sink);
174 174
175 /** 175 /**
176 * Returns true if there is a terminal attached to stdout. 176 * Returns true if there is a terminal attached to stdout.
177 */ 177 */
178 bool get hasTerminal => _hasTerminal(_fd); 178 bool get hasTerminal => _hasTerminal(_fd);
179 179
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 cancelOnError: true); 255 cancelOnError: true);
256 return completer.future; 256 return completer.future;
257 } 257 }
258 258
259 Future close() { 259 Future close() {
260 _file.closeSync(); 260 _file.closeSync();
261 return new Future.value(); 261 return new Future.value();
262 } 262 }
263 } 263 }
264 264
265 class _StdSink implements IOSink { 265 class _StdSinkHelper implements IOSink {
266 final IOSink _sink; 266 final IOSink _sink;
267 final bool _isTranslatable;
267 268
268 _StdSink(this._sink); 269 _StdSinkHelper(this._sink, this._isTranslatable);
269 270
270 Encoding get encoding => _sink.encoding; 271 Encoding get encoding => _sink.encoding;
271 void set encoding(Encoding encoding) { 272 void set encoding(Encoding encoding) {
272 _sink.encoding = encoding; 273 _sink.encoding = encoding;
273 } 274 }
274 void write(object) { _sink.write(object); } 275
275 void writeln([object = "" ]) { _sink.writeln(object); } 276 void set _translation(_FileTranslation t) {
276 void writeAll(objects, [sep = ""]) { _sink.writeAll(objects, sep); } 277 if (_isTranslatable) {
277 void add(List<int> data) { _sink.add(data); } 278 _sink._target._file.translation = t;
279 }
280 }
281
282 void write(object) {
283 _translation = _FileTranslation.text;
284 _sink.write(object);
285 }
286 void writeln([object = "" ]) {
287 _translation = _FileTranslation.text;
288 _sink.writeln(object);
289 }
290 void writeAll(objects, [sep = ""]) {
291 _translation = _FileTranslation.text;
292 _sink.writeAll(objects, sep);
293 }
294 void add(List<int> data) {
295 _translation = _FileTranslation.binary;
296 _sink.add(data);
297 }
278 void addError(error, [StackTrace stackTrace]) { 298 void addError(error, [StackTrace stackTrace]) {
279 _sink.addError(error, stackTrace); 299 _sink.addError(error, stackTrace);
280 } 300 }
281 void writeCharCode(int charCode) { _sink.writeCharCode(charCode); } 301 void writeCharCode(int charCode) {
282 Future addStream(Stream<List<int>> stream) => _sink.addStream(stream); 302 _translation = _FileTranslation.text;
303 _sink.writeCharCode(charCode);
304 }
305 Future addStream(Stream<List<int>> stream) {
306 _translation = _FileTranslation.binary;
307 return _sink.addStream(stream);
308 }
283 Future flush() => _sink.flush(); 309 Future flush() => _sink.flush();
284 Future close() => _sink.close(); 310 Future close() => _sink.close();
285 Future get done => _sink.done; 311 Future get done => _sink.done;
286 } 312 }
287 313
314 class _StdFileSink extends _StdSinkHelper {
315 // The target of `sink` is expected to be a _StdConsumer.
316 _StdFileSink(IOSink sink) : super(sink, true);
317 }
318
319 class _StdSocketSink extends _StdSinkHelper {
320 _StdSocketSink(IOSink sink) : super(sink, false);
321 }
322
288 /// The type of object a standard IO stream is attached to. 323 /// The type of object a standard IO stream is attached to.
289 class StdioType { 324 class StdioType {
290 static const StdioType TERMINAL = const StdioType._("terminal"); 325 static const StdioType TERMINAL = const StdioType._("terminal");
291 static const StdioType PIPE = const StdioType._("pipe"); 326 static const StdioType PIPE = const StdioType._("pipe");
292 static const StdioType FILE = const StdioType._("file"); 327 static const StdioType FILE = const StdioType._("file");
293 static const StdioType OTHER = const StdioType._("other"); 328 static const StdioType OTHER = const StdioType._("other");
294 final String name; 329 final String name;
295 const StdioType._(this.name); 330 const StdioType._(this.name);
296 String toString() => "StdioType: $name"; 331 String toString() => "StdioType: $name";
297 } 332 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 } 404 }
370 405
371 406
372 class _StdIOUtils { 407 class _StdIOUtils {
373 external static _getStdioOutputStream(int fd); 408 external static _getStdioOutputStream(int fd);
374 external static Stdin _getStdioInputStream(); 409 external static Stdin _getStdioInputStream();
375 /// Returns the socket type or `null` if [socket] is not a builtin socket. 410 /// Returns the socket type or `null` if [socket] is not a builtin socket.
376 external static int _socketType(Socket socket); 411 external static int _socketType(Socket socket);
377 external static _getStdioHandleType(int fd); 412 external static _getStdioHandleType(int fd);
378 } 413 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | tests/standalone/io/console_unicode_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698