mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
896d041281
commit
65b11a04f1
2 changed files with 19 additions and 9 deletions
|
@ -531,6 +531,7 @@ console_set_winsize(VALUE io, VALUE size)
|
||||||
#if defined _WIN32
|
#if defined _WIN32
|
||||||
HANDLE wh;
|
HANDLE wh;
|
||||||
int newrow, newcol;
|
int newrow, newcol;
|
||||||
|
BOOL ret;
|
||||||
#endif
|
#endif
|
||||||
VALUE row, col, xpixel, ypixel;
|
VALUE row, col, xpixel, ypixel;
|
||||||
const VALUE *sz;
|
const VALUE *sz;
|
||||||
|
@ -568,17 +569,21 @@ console_set_winsize(VALUE io, VALUE size)
|
||||||
if (!GetConsoleScreenBufferInfo(wh, &ws)) {
|
if (!GetConsoleScreenBufferInfo(wh, &ws)) {
|
||||||
rb_syserr_fail(LAST_ERROR, "GetConsoleScreenBufferInfo");
|
rb_syserr_fail(LAST_ERROR, "GetConsoleScreenBufferInfo");
|
||||||
}
|
}
|
||||||
if ((ws.dwSize.X < newcol && (ws.dwSize.X = newcol, 1)) ||
|
ws.dwSize.X = newcol;
|
||||||
(ws.dwSize.Y < newrow && (ws.dwSize.Y = newrow, 1))) {
|
ret = SetConsoleScreenBufferSize(wh, ws.dwSize);
|
||||||
if (!SetConsoleScreenBufferSize(wh, ws.dwSize)) {
|
|
||||||
rb_syserr_fail(LAST_ERROR, "SetConsoleScreenBufferInfo");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ws.srWindow.Left = 0;
|
ws.srWindow.Left = 0;
|
||||||
ws.srWindow.Top = 0;
|
ws.srWindow.Top = 0;
|
||||||
ws.srWindow.Right = newcol;
|
ws.srWindow.Right = newcol-1;
|
||||||
ws.srWindow.Bottom = newrow;
|
ws.srWindow.Bottom = newrow-1;
|
||||||
if (!SetConsoleWindowInfo(wh, FALSE, &ws.srWindow)) {
|
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");
|
rb_syserr_fail(LAST_ERROR, "SetConsoleWindowInfo");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -317,6 +317,11 @@ defined?(IO.console) and TestIO_Console.class_eval do
|
||||||
def test_set_winsize_console
|
def test_set_winsize_console
|
||||||
s = IO.console.winsize
|
s = IO.console.winsize
|
||||||
assert_nothing_raised(TypeError) {IO.console.winsize = s}
|
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
|
end
|
||||||
|
|
||||||
def test_close
|
def test_close
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue