1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2015-03-21 06:01:29 +00:00
parent 0d8e684d32
commit add8e1f5bb
3 changed files with 20 additions and 11 deletions

View file

@ -1,3 +1,14 @@
Sat Mar 21 15:01:26 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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]
Fri Mar 20 18:41:03 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* proc.c (respond_to_missing_p): check if the receiver responds to

View file

@ -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;

2
io.c
View file

@ -12078,7 +12078,7 @@ rb_readwrite_sys_fail(int writable, const char *mesg)
* Example:
*
* require 'io/console'
* rows, columns = $stdin.winsize
* rows, columns = $stdout.winsize
* puts "Your screen is #{columns} wide and #{rows} tall"
*/