Chromium Code Reviews| 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 @patch static Stdin _getStdioInputStream() { | 6 @patch 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: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 } | 76 } |
| 77 return result; | 77 return result; |
| 78 } | 78 } |
| 79 @patch void set lineMode(bool enabled) { | 79 @patch void set lineMode(bool enabled) { |
| 80 var result = _setLineMode(enabled); | 80 var result = _setLineMode(enabled); |
| 81 if (result is OSError) { | 81 if (result is OSError) { |
| 82 throw new StdinException("Error setting terminal line mode", result); | 82 throw new StdinException("Error setting terminal line mode", result); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 @patch bool get supportsAnsiEscapes { | |
| 87 var result = _supportsAnsiEscapes(); | |
| 88 if (result is OSError) { | |
| 89 throw new StdinException("Error determining ANSI support", result); | |
| 90 } | |
| 91 return result; | |
| 92 } | |
| 93 | |
| 86 static _echoMode() native "Stdin_GetEchoMode"; | 94 static _echoMode() native "Stdin_GetEchoMode"; |
| 87 static _setEchoMode(bool enabled) native "Stdin_SetEchoMode"; | 95 static _setEchoMode(bool enabled) native "Stdin_SetEchoMode"; |
| 88 static _lineMode() native "Stdin_GetLineMode"; | 96 static _lineMode() native "Stdin_GetLineMode"; |
| 89 static _setLineMode(bool enabled) native "Stdin_SetLineMode"; | 97 static _setLineMode(bool enabled) native "Stdin_SetLineMode"; |
| 90 static _readByte() native "Stdin_ReadByte"; | 98 static _readByte() native "Stdin_ReadByte"; |
| 99 static _supportsAnsiEscapes() native "Stdin_AnsiSupported"; | |
| 91 } | 100 } |
| 92 | 101 |
| 93 @patch class Stdout { | 102 @patch class Stdout { |
| 94 @patch bool _hasTerminal(int fd) { | 103 @patch bool _hasTerminal(int fd) { |
| 95 try { | 104 try { |
| 96 _terminalSize(fd); | 105 _terminalSize(fd); |
| 97 return true; | 106 return true; |
| 98 } catch (_) { | 107 } catch (_) { |
| 99 return false; | 108 return false; |
| 100 } | 109 } |
| 101 } | 110 } |
| 102 | 111 |
| 103 @patch int _terminalColumns(int fd) => _terminalSize(fd)[0]; | 112 @patch int _terminalColumns(int fd) => _terminalSize(fd)[0]; |
| 104 @patch int _terminalLines(int fd) => _terminalSize(fd)[1]; | 113 @patch int _terminalLines(int fd) => _terminalSize(fd)[1]; |
| 105 | 114 |
| 106 static List _terminalSize(int fd) { | 115 static List _terminalSize(int fd) { |
| 107 var size = _getTerminalSize(fd); | 116 var size = _getTerminalSize(fd); |
| 108 if (size is! List) { | 117 if (size is! List) { |
| 109 throw new StdoutException("Could not get terminal size", size); | 118 throw new StdoutException("Could not get terminal size", size); |
| 110 } | 119 } |
| 111 return size; | 120 return size; |
| 112 } | 121 } |
| 113 | 122 |
| 114 static _getTerminalSize(int fd) native "Stdout_GetTerminalSize"; | 123 static _getTerminalSize(int fd) native "Stdout_GetTerminalSize"; |
| 124 | |
| 125 @patch static bool _supportsAnsiEscapes(int fd) { | |
| 126 var result = _getAnsiSupported(fd); | |
| 127 if (result is! bool) { | |
| 128 throw new StdoutException("Error determining ANSI support", result); | |
|
siva
2017/03/17 23:54:24
Would it make sense to include the 'fd' in the exc
| |
| 129 } | |
| 130 return result; | |
| 131 } | |
| 132 | |
| 133 static _getAnsiSupported(int fd) native "Stdout_AnsiSupported"; | |
| 115 } | 134 } |
| 116 | 135 |
| 117 | 136 |
| 118 _getStdioHandle(_NativeSocket socket, int num) native "Socket_GetStdioHandle"; | 137 _getStdioHandle(_NativeSocket socket, int num) native "Socket_GetStdioHandle"; |
| 119 _getSocketType(_NativeSocket nativeSocket) native "Socket_GetType"; | 138 _getSocketType(_NativeSocket nativeSocket) native "Socket_GetType"; |
| OLD | NEW |