ruby-changes:47728
From: nobu <ko1@a...>
Date: Tue, 12 Sep 2017 05:10:41 +0900 (JST)
Subject: [ruby-changes:47728] nobu:r59844 (trunk): console.c: set winsize on Windows
nobu 2017-09-12 05:10:34 +0900 (Tue, 12 Sep 2017) New Revision: 59844 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59844 Log: console.c: set winsize on Windows * ext/io/console/console.c (console_set_winsize): retry shrinking window and screen buffer. [ruby-core:82741] [Bug #13888] Modified files: trunk/ext/io/console/console.c trunk/test/io/console/test_io_console.rb Index: ext/io/console/console.c =================================================================== --- ext/io/console/console.c (revision 59843) +++ ext/io/console/console.c (revision 59844) @@ -531,6 +531,7 @@ console_set_winsize(VALUE io, VALUE size https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L531 #if defined _WIN32 HANDLE wh; int newrow, newcol; + BOOL ret; #endif VALUE row, col, xpixel, ypixel; const VALUE *sz; @@ -568,17 +569,21 @@ console_set_winsize(VALUE io, VALUE size https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L569 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)) { - rb_syserr_fail(LAST_ERROR, "SetConsoleScreenBufferInfo"); - } - } + ws.dwSize.X = newcol; + ret = SetConsoleScreenBufferSize(wh, ws.dwSize); ws.srWindow.Left = 0; ws.srWindow.Top = 0; - ws.srWindow.Right = newcol; - ws.srWindow.Bottom = newrow; - if (!SetConsoleWindowInfo(wh, FALSE, &ws.srWindow)) { + ws.srWindow.Right = newcol-1; + ws.srWindow.Bottom = newrow-1; + if (!SetConsoleWindowInfo(wh, TRUE, &ws.srWindow)) { + rb_syserr_fail(LAST_ERROR, "SetConsoleWindowInfo"); + } + /* retry when shrinking buffer after shrunk window */ + if (!ret && !SetConsoleScreenBufferSize(wh, ws.dwSize)) { + rb_syserr_fail(LAST_ERROR, "SetConsoleScreenBufferInfo"); + } + /* remove scrollbar if possible */ + if (!SetConsoleWindowInfo(wh, TRUE, &ws.srWindow)) { rb_syserr_fail(LAST_ERROR, "SetConsoleWindowInfo"); } #endif Index: test/io/console/test_io_console.rb =================================================================== --- test/io/console/test_io_console.rb (revision 59843) +++ test/io/console/test_io_console.rb (revision 59844) @@ -317,6 +317,11 @@ defined?(IO.console) and TestIO_Console. https://github.com/ruby/ruby/blob/trunk/test/io/console/test_io_console.rb#L317 def test_set_winsize_console s = IO.console.winsize assert_nothing_raised(TypeError) {IO.console.winsize = s} + bug = '[ruby-core:82741] [Bug #13888]' + IO.console.winsize = [s[0], s[1]+1] + assert_equal([s[0], s[1]+1], IO.console.winsize, bug) + IO.console.winsize = s + assert_equal(s, IO.console.winsize, bug) end def test_close -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/