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

Unified Diff: runtime/bin/stdio_patch.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/stdio_macos.cc ('k') | runtime/bin/stdio_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/stdio_patch.dart
diff --git a/runtime/bin/stdio_patch.dart b/runtime/bin/stdio_patch.dart
index 5d5cdaf7087a6b4aeac27e2ccf79952e5dea1ff4..2a10eff51f3202a00fc8dd4db5225538dfb19562 100644
--- a/runtime/bin/stdio_patch.dart
+++ b/runtime/bin/stdio_patch.dart
@@ -16,15 +16,22 @@ patch class _StdIOUtils {
}
}
- static IOSink _getStdioOutputStream(int fd) {
+ static _getStdioOutputStream(int fd) {
+ wrap(sink) {
+ if (fd == 1) {
+ return new Stdout._(sink);
+ } else {
+ return new _StdSink(sink);
+ }
+ }
assert(fd == 1 || fd == 2);
switch (_getStdioHandleType(fd)) {
case _STDIO_HANDLE_TYPE_TERMINAL:
case _STDIO_HANDLE_TYPE_PIPE:
case _STDIO_HANDLE_TYPE_SOCKET:
- return new _StdSink(new _Socket._writePipe(fd));
+ return wrap(new _Socket._writePipe(fd));
case _STDIO_HANDLE_TYPE_FILE:
- return new _StdSink(new IOSink(new _FileStreamConsumer.fromStdio(fd)));
+ return wrap(new IOSink(new _FileStreamConsumer.fromStdio(fd)));
default:
throw new FileSystemException("Unsupported stdin type");
}
@@ -54,6 +61,30 @@ patch class Stdin {
static void set _lineMode(bool enabled) native "Stdin_SetLineMode";
}
+patch class Stdout {
+ /* patch */ bool get hasTerminal {
+ try {
+ _terminalSize;
+ return true;
+ } catch (_) {
+ return false;
+ }
+ }
+
+ /* patch */ int get terminalColumns => _terminalSize[0];
+ /* patch */ int get terminalLines => _terminalSize[1];
+
+ static List get _terminalSize {
+ var size = _getTerminalSize();
+ if (size is! List) {
+ throw new StdoutException("Could not get terminal size", size);
+ }
+ return size;
+ }
+
+ static List _getTerminalSize() native "Stdout_GetTerminalSize";
+}
+
_getStdioHandle(_NativeSocket socket, int num) native "Socket_GetStdioHandle";
_getStdioHandleType(int num) native "File_GetStdioHandleType";
« no previous file with comments | « runtime/bin/stdio_macos.cc ('k') | runtime/bin/stdio_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698