[前][次][番号順一覧][スレッド一覧]

ruby-changes:37960

From: nobu <ko1@a...>
Date: Sat, 21 Mar 2015 15:01:43 +0900 (JST)
Subject: [ruby-changes:37960] nobu:r50041 (trunk): console.c: winsize on Windows

nobu	2015-03-21 15:01:29 +0900 (Sat, 21 Mar 2015)

  New Revision: 50041

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50041

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/ext/io/console/console.c
    trunk/io.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50040)
+++ ChangeLog	(revision 50041)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Mar 21 15:01:26 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* proc.c (respond_to_missing_p): check if the receiver responds to
Index: io.c
===================================================================
--- io.c	(revision 50040)
+++ io.c	(revision 50041)
@@ -12078,7 +12078,7 @@ rb_readwrite_sys_fail(int writable, cons https://github.com/ruby/ruby/blob/trunk/io.c#L12078
  *  Example:
  *
  *    require 'io/console'
- *    rows, columns = $stdin.winsize
+ *    rows, columns = $stdout.winsize
  *    puts "Your screen is #{columns} wide and #{rows} tall"
  */
 
Index: ext/io/console/console.c
===================================================================
--- ext/io/console/console.c	(revision 50040)
+++ ext/io/console/console.c	(revision 50041)
@@ -525,16 +525,14 @@ console_set_winsize(VALUE io, VALUE size https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L525
     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 https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L542
 #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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]