summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2017-04-30 20:40:34 +0800
committerruki <[email protected]>2017-04-30 20:40:34 +0800
commitdb2fa19714ea95b98fa9c848d3ea69a68fb69f30 (patch)
tree8e62e89f3ddffe5fc6f7f780d03a812b07f658c4 /core/src
parent2d077a73b654541e76107c5bb01c402572e484c1 (diff)
impl getwinsize for windows
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/os/getwinsize.c25
1 files changed, 16 insertions, 9 deletions
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 <windows.h>
+#else
# include <sys/ioctl.h>
# include <errno.h> // for errno
# include <unistd.h> // 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()