diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-03-21 06:01:29 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-03-21 06:01:29 +0000 |
commit | add8e1f5bb59dc8aa35d0493b19af3bebe4e4876 (patch) | |
tree | 2f56817754e219ed19087639fe1f3b650b0d1348 /ext | |
parent | 0d8e684d3200763c49d114d5bdd943f78547c19b (diff) | |
download | ruby-add8e1f5bb59dc8aa35d0493b19af3bebe4e4876.tar.gz |
console.c: winsize on Windows
* ext/io/console/console.c (console_set_winsize): use handle for
writing. GetConsoleScreenBufferInfo seems failing on a handle
for reading.
* io.c: [DOC] update the example of IO#winsize to use $stdout
instead of $stdin, which does not work on Windows. a patch by
Jan Lelis <mail AT janlelis.de> at [ruby-core:68574].
[Bug #10986]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/io/console/console.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c index b360090b66..c5d61eb39d 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -525,16 +525,14 @@ console_set_winsize(VALUE io, VALUE size) int newrow, newcol; #endif VALUE row, col, xpixel, ypixel; -#if defined TIOCSWINSZ int fd; -#endif GetOpenFile(io, fptr); size = rb_Array(size); rb_scan_args((int)RARRAY_LEN(size), RARRAY_PTR(size), "22", &row, &col, &xpixel, &ypixel); -#if defined TIOCSWINSZ fd = GetWriteFD(fptr); +#if defined TIOCSWINSZ ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0; #define SET(m) ws.ws_##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m) SET(row); @@ -544,24 +542,24 @@ console_set_winsize(VALUE io, VALUE size) #undef SET if (!setwinsize(fd, &ws)) rb_sys_fail(0); #elif defined _WIN32 - wh = (HANDLE)rb_w32_get_osfhandle(GetReadFD(fptr)); + wh = (HANDLE)rb_w32_get_osfhandle(fd); newrow = (SHORT)NUM2UINT(row); newcol = (SHORT)NUM2UINT(col); - if (!getwinsize(GetReadFD(fptr), &ws)) { - rb_sys_fail("GetConsoleScreenBufferInfo"); + if (!GetConsoleScreenBufferInfo(wh, &ws)) { + rb_syserr_fail(LAST_ERROR, "GetConsoleScreenBufferInfo"); } if ((ws.dwSize.X < newcol && (ws.dwSize.X = newcol, 1)) || (ws.dwSize.Y < newrow && (ws.dwSize.Y = newrow, 1))) { - if (!(SetConsoleScreenBufferSize(wh, ws.dwSize) || SET_LAST_ERROR)) { - rb_sys_fail("SetConsoleScreenBufferInfo"); + if (!SetConsoleScreenBufferSize(wh, ws.dwSize)) { + rb_syserr_fail(LAST_ERROR, "SetConsoleScreenBufferInfo"); } } ws.srWindow.Left = 0; ws.srWindow.Top = 0; ws.srWindow.Right = newcol; ws.srWindow.Bottom = newrow; - if (!(SetConsoleWindowInfo(wh, FALSE, &ws.srWindow) || SET_LAST_ERROR)) { - rb_sys_fail("SetConsoleWindowInfo"); + if (!SetConsoleWindowInfo(wh, FALSE, &ws.srWindow)) { + rb_syserr_fail(LAST_ERROR, "SetConsoleWindowInfo"); } #endif return io; |