From bf132771ae56b6d5c8e5d3d1c33c3b10c9862548 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Tue, 28 Apr 2009 15:14:52 +1000 Subject: libbb/xfuncs.c: reimplement get_terminal_width_height to understand Windows console --- libbb/xfuncs.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 3738d6bcf..06bba0fe3 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -626,13 +626,23 @@ void selinux_or_die(void) /* It is perfectly ok to pass in a NULL for either width or for * height, in which case that value will not be set. */ #ifdef __MINGW32__ +#include int get_terminal_width_height(const int fd, int *width, int *height) { - /* FIXME: support for Windows console */ + HANDLE console; + CONSOLE_SCREEN_BUFFER_INFO sbi; + + console = GetStdHandle(STD_OUTPUT_HANDLE); + if (console == INVALID_HANDLE_VALUE || !console) + return -1; + + GetConsoleScreenBufferInfo(console, &sbi); + if (width) - *width = 80; + *width = sbi.srWindow.Right - sbi.srWindow.Left; if (height) - *height = 25; + *height = sbi.srWindow.Bottom - sbi.srWindow.Top; + return 0; } #else int get_terminal_width_height(const int fd, int *width, int *height) -- cgit v1.2.3-55-g6feb