winsize=(p1)
public
Tries to set console size. The effect
depends on the platform and the running environment.
You must require ‘io/console’ to use this method.
Show source
static VALUE
console_set_winsize(VALUE io, VALUE size)
{
rb_io_t *fptr;
rb_console_size_t ws;
HANDLE wh;
int newrow, newcol;
VALUE row, col, xpixel, ypixel;
int fd;
GetOpenFile(io, fptr);
size = rb_Array(size);
rb_scan_args((int)RARRAY_LEN(size), RARRAY_PTR(size), "22",
&row, &col, &xpixel, &ypixel);
fd = GetWriteFD(fptr);
ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0;
SET(row);
SET(col);
SET(xpixel);
SET(ypixel);
if (!setwinsize(fd, &ws)) rb_sys_fail(0);
wh = (HANDLE)rb_w32_get_osfhandle(GetReadFD(fptr));
newrow = (SHORT)NUM2UINT(row);
newcol = (SHORT)NUM2UINT(col);
if (!getwinsize(GetReadFD(fptr), &ws)) {
rb_sys_fail("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");
}
}
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");
}
return io;
}