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

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

Issue 102123010: Add getter for hasTerminal, terminalColumns and terminalLines on stdout. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add include of thread.h and fix io_patch. Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/lib/io_patch.dart ('k') | tests/standalone/io/stdin_sync_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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 /** 152 /**
153 * Synchronously read a byte from stdin. This call will block until a byte is 153 * Synchronously read a byte from stdin. This call will block until a byte is
154 * available. 154 * available.
155 * 155 *
156 * If at end of file, -1 is returned. 156 * If at end of file, -1 is returned.
157 */ 157 */
158 external int readByteSync(); 158 external int readByteSync();
159 } 159 }
160 160
161 161
162 /**
163 * [Stdout] exposes methods to query the terminal for properties.
164 *
165 * Use [hasTerminal] to test if there is a terminal associated to stdout.
166 */
167 class Stdout extends _StdSink implements IOSink {
168 Stdout._(IOSink sink) : super(sink);
169
170 /**
171 * Returns true if there is a terminal attached to stdout.
172 */
173 external bool get hasTerminal;
174
175 /**
176 * Get the number of columns of the terminal.
177 *
178 * If no terminal is attached to stdout, a [StdoutException] is thrown. See
179 * [hasTerminal] for more info.
180 */
181 external int get terminalColumns;
182
183 /**
184 * Get the number of lines of the terminal.
185 *
186 * If no terminal is attached to stdout, a [StdoutException] is thrown. See
187 * [hasTerminal] for more info.
188 */
189 external int get terminalLines;
190 }
191
192
193 class StdoutException implements IOException {
194 final String message;
195 final OSError osError;
196
197 const StdoutException(this.message, [this.osError]);
198
199 String toString() {
200 return "StdoutException: $message${osError == null ? "" : ", $osError"}";
201 }
202 }
203
204
162 class _StdSink implements IOSink { 205 class _StdSink implements IOSink {
163 final IOSink _sink; 206 final IOSink _sink;
164 207
165 _StdSink(IOSink this._sink); 208 _StdSink(IOSink this._sink);
166 209
167 Encoding get encoding => _sink.encoding; 210 Encoding get encoding => _sink.encoding;
168 void set encoding(Encoding encoding) { 211 void set encoding(Encoding encoding) {
169 _sink.encoding = encoding; 212 _sink.encoding = encoding;
170 } 213 }
171 void write(object) => _sink.write(object); 214 void write(object) => _sink.write(object);
(...skipping 15 matching lines...) Expand all
187 static const StdioType PIPE = const StdioType._("pipe"); 230 static const StdioType PIPE = const StdioType._("pipe");
188 static const StdioType FILE = const StdioType._("file"); 231 static const StdioType FILE = const StdioType._("file");
189 static const StdioType OTHER = const StdioType._("other"); 232 static const StdioType OTHER = const StdioType._("other");
190 final String name; 233 final String name;
191 const StdioType._(String this.name); 234 const StdioType._(String this.name);
192 String toString() => "StdioType: $name"; 235 String toString() => "StdioType: $name";
193 } 236 }
194 237
195 238
196 Stdin _stdin; 239 Stdin _stdin;
197 IOSink _stdout; 240 Stdout _stdout;
198 IOSink _stderr; 241 IOSink _stderr;
199 242
200 243
201 /// The standard input stream of data read by this program. 244 /// The standard input stream of data read by this program.
202 Stdin get stdin { 245 Stdin get stdin {
203 if (_stdin == null) { 246 if (_stdin == null) {
204 _stdin = _StdIOUtils._getStdioInputStream(); 247 _stdin = _StdIOUtils._getStdioInputStream();
205 } 248 }
206 return _stdin; 249 return _stdin;
207 } 250 }
208 251
209 252
210 /// The standard output stream of data written by this program. 253 /// The standard output stream of data written by this program.
211 IOSink get stdout { 254 Stdout get stdout {
212 if (_stdout == null) { 255 if (_stdout == null) {
213 _stdout = _StdIOUtils._getStdioOutputStream(1); 256 _stdout = _StdIOUtils._getStdioOutputStream(1);
214 } 257 }
215 return _stdout; 258 return _stdout;
216 } 259 }
217 260
218 261
219 /// The standard output stream of errors written by this program. 262 /// The standard output stream of errors written by this program.
220 IOSink get stderr { 263 IOSink get stderr {
221 if (_stderr == null) { 264 if (_stderr == null) {
(...skipping 28 matching lines...) Expand all
250 } 293 }
251 } catch (e) { 294 } catch (e) {
252 // Only the interface implemented, _sink not available. 295 // Only the interface implemented, _sink not available.
253 } 296 }
254 } 297 }
255 return StdioType.OTHER; 298 return StdioType.OTHER;
256 } 299 }
257 300
258 301
259 class _StdIOUtils { 302 class _StdIOUtils {
260 external static IOSink _getStdioOutputStream(int fd); 303 external static _getStdioOutputStream(int fd);
261 external static Stdin _getStdioInputStream(); 304 external static Stdin _getStdioInputStream();
262 external static int _socketType(nativeSocket); 305 external static int _socketType(nativeSocket);
263 } 306 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/lib/io_patch.dart ('k') | tests/standalone/io/stdin_sync_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698