| 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 patch class _StdIOUtils { | 5 patch class _StdIOUtils { |
| 6 static Stdin _getStdioInputStream() { | 6 static Stdin _getStdioInputStream() { |
| 7 switch (_getStdioHandleType(0)) { | 7 switch (_getStdioHandleType(0)) { |
| 8 case _STDIO_HANDLE_TYPE_TERMINAL: | 8 case _STDIO_HANDLE_TYPE_TERMINAL: |
| 9 case _STDIO_HANDLE_TYPE_PIPE: | 9 case _STDIO_HANDLE_TYPE_PIPE: |
| 10 case _STDIO_HANDLE_TYPE_SOCKET: | 10 case _STDIO_HANDLE_TYPE_SOCKET: |
| 11 return new Stdin._(new _Socket._readPipe(0)); | 11 return new Stdin._(new _Socket._readPipe(0)); |
| 12 case _STDIO_HANDLE_TYPE_FILE: | 12 case _STDIO_HANDLE_TYPE_FILE: |
| 13 return new Stdin._(new _FileStream.forStdin()); | 13 return new Stdin._(new _FileStream.forStdin()); |
| 14 default: | 14 default: |
| 15 throw new FileSystemException("Unsupported stdin type"); | 15 throw new FileSystemException("Unsupported stdin type"); |
| 16 } | 16 } |
| 17 } | 17 } |
| 18 | 18 |
| 19 static _getStdioOutputStream(int fd) { | 19 static _getStdioOutputStream(int fd) { |
| 20 wrap(sink) { | |
| 21 if (fd == 1) { | |
| 22 return new Stdout._(sink); | |
| 23 } else { | |
| 24 return new _StdSink(sink); | |
| 25 } | |
| 26 } | |
| 27 assert(fd == 1 || fd == 2); | 20 assert(fd == 1 || fd == 2); |
| 28 switch (_getStdioHandleType(fd)) { | 21 switch (_getStdioHandleType(fd)) { |
| 29 case _STDIO_HANDLE_TYPE_TERMINAL: | 22 case _STDIO_HANDLE_TYPE_TERMINAL: |
| 30 case _STDIO_HANDLE_TYPE_PIPE: | 23 case _STDIO_HANDLE_TYPE_PIPE: |
| 31 case _STDIO_HANDLE_TYPE_SOCKET: | 24 case _STDIO_HANDLE_TYPE_SOCKET: |
| 32 case _STDIO_HANDLE_TYPE_FILE: | 25 case _STDIO_HANDLE_TYPE_FILE: |
| 33 return wrap(new IOSink(new _FileStreamConsumer.fromStdio(fd))); | 26 return new Stdout._(new IOSink(new _StdConsumer(fd)), fd); |
| 34 default: | 27 default: |
| 35 throw new FileSystemException("Unsupported stdin type"); | 28 throw new FileSystemException("Unsupported stdin type"); |
| 36 } | 29 } |
| 37 } | 30 } |
| 38 | 31 |
| 39 static int _socketType(nativeSocket) { | 32 static int _socketType(nativeSocket) { |
| 40 var result = _getSocketType(nativeSocket); | 33 var result = _getSocketType(nativeSocket); |
| 41 if (result is OSError) { | 34 if (result is OSError) { |
| 42 throw new FileSystemException("Error retreiving socket type", result); | 35 throw new FileSystemException("Error retreiving socket type", result); |
| 43 } | 36 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 56 /* patch */ bool get lineMode => _lineMode; | 49 /* patch */ bool get lineMode => _lineMode; |
| 57 /* patch */ void set lineMode(bool enabled) { _lineMode = enabled; } | 50 /* patch */ void set lineMode(bool enabled) { _lineMode = enabled; } |
| 58 | 51 |
| 59 static bool get _echoMode native "Stdin_GetEchoMode"; | 52 static bool get _echoMode native "Stdin_GetEchoMode"; |
| 60 static void set _echoMode(bool enabled) native "Stdin_SetEchoMode"; | 53 static void set _echoMode(bool enabled) native "Stdin_SetEchoMode"; |
| 61 static bool get _lineMode native "Stdin_GetLineMode"; | 54 static bool get _lineMode native "Stdin_GetLineMode"; |
| 62 static void set _lineMode(bool enabled) native "Stdin_SetLineMode"; | 55 static void set _lineMode(bool enabled) native "Stdin_SetLineMode"; |
| 63 } | 56 } |
| 64 | 57 |
| 65 patch class Stdout { | 58 patch class Stdout { |
| 66 /* patch */ bool get hasTerminal { | 59 /* patch */ bool _hasTerminal(int fd) { |
| 67 try { | 60 try { |
| 68 _terminalSize; | 61 _terminalSize(fd); |
| 69 return true; | 62 return true; |
| 70 } catch (_) { | 63 } catch (_) { |
| 71 return false; | 64 return false; |
| 72 } | 65 } |
| 73 } | 66 } |
| 74 | 67 |
| 75 /* patch */ int get terminalColumns => _terminalSize[0]; | 68 /* patch */ int _terminalColumns(int fd) => _terminalSize(fd)[0]; |
| 76 /* patch */ int get terminalLines => _terminalSize[1]; | 69 /* patch */ int _terminalLines(int fd) => _terminalSize(fd)[1]; |
| 77 | 70 |
| 78 static List get _terminalSize { | 71 static List _terminalSize(int fd) { |
| 79 var size = _getTerminalSize(); | 72 var size = _getTerminalSize(fd); |
| 80 if (size is! List) { | 73 if (size is! List) { |
| 81 throw new StdoutException("Could not get terminal size", size); | 74 throw new StdoutException("Could not get terminal size", size); |
| 82 } | 75 } |
| 83 return size; | 76 return size; |
| 84 } | 77 } |
| 85 | 78 |
| 86 static _getTerminalSize() native "Stdout_GetTerminalSize"; | 79 static _getTerminalSize(int fd) native "Stdout_GetTerminalSize"; |
| 87 } | 80 } |
| 88 | 81 |
| 89 | 82 |
| 90 _getStdioHandle(_NativeSocket socket, int num) native "Socket_GetStdioHandle"; | 83 _getStdioHandle(_NativeSocket socket, int num) native "Socket_GetStdioHandle"; |
| 91 _getSocketType(_NativeSocket nativeSocket) native "Socket_GetType"; | 84 _getSocketType(_NativeSocket nativeSocket) native "Socket_GetType"; |
| OLD | NEW |