From db2fa19714ea95b98fa9c848d3ea69a68fb69f30 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 30 Apr 2017 20:40:34 +0800 Subject: impl getwinsize for windows --- core/src/xmake/os/getwinsize.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'core/src') diff --git a/core/src/xmake/os/getwinsize.c b/core/src/xmake/os/getwinsize.c index 041150070..be8fbaf2d 100644 --- a/core/src/xmake/os/getwinsize.c +++ b/core/src/xmake/os/getwinsize.c @@ -33,7 +33,9 @@ * includes */ #include "prefix.h" -#ifndef TB_CONFIG_OS_WINDOWS +#ifdef TB_CONFIG_OS_WINDOWS +# include +#else # include # include // for errno # include // for STDOUT_FILENO @@ -49,19 +51,24 @@ tb_int_t xm_os_getwinsize(lua_State* lua) // check tb_assert_and_check_return_val(lua, 0); - // init default window size - unsigned short w = -1, h = -1; + // init default window size (we will not consider winsize limit if cannot get it) + tb_int_t w = -1, h = -1; // get winsize -#ifndef TB_CONFIG_OS_WINDOWS - struct winsize size = {0}; - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) == 0) +#ifdef TB_CONFIG_OS_WINDOWS + CONSOLE_SCREEN_BUFFER_INFO csbi; + if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) { - w = size.ws_col; - h = size.ws_row; + w = (tb_int_t)csbi.dwSize.X; + h = (tb_int_t)csbi.dwSize.Y; } #else - // we will not consider winsize limit if cannot get it + struct winsize size; + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) == 0) + { + w = (tb_int_t)size.ws_col; + h = (tb_int_t)size.ws_row; + } #endif /* local winsize = os.getwinsize() -- cgit v1.3.1