diff options
author | Ron Yorston <rmy@pobox.com> | 2012-02-20 10:41:31 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2012-02-20 10:41:31 +0000 |
commit | c6ff39ccc4e52fb860f2bfe436c5ac1c114aadd7 (patch) | |
tree | f81e95d16640882bd35202370626b1a0808343f7 | |
parent | 6fe28f11f83d489e8f5904a75a90008ca94c1437 (diff) | |
download | busybox-w32-c6ff39ccc4e52fb860f2bfe436c5ac1c114aadd7.tar.gz busybox-w32-c6ff39ccc4e52fb860f2bfe436c5ac1c114aadd7.tar.bz2 busybox-w32-c6ff39ccc4e52fb860f2bfe436c5ac1c114aadd7.zip |
Add code to find console dimensions in WIN32
-rw-r--r-- | include/mingw.h | 2 | ||||
-rw-r--r-- | libbb/xfuncs.c | 4 | ||||
-rw-r--r-- | win32/winansi.c | 17 |
3 files changed, 23 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h index 6fe5d4017..49de6cb5e 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -152,6 +152,8 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format | |||
152 | #define printf(...) winansi_printf(__VA_ARGS__) | 152 | #define printf(...) winansi_printf(__VA_ARGS__) |
153 | #define fprintf(...) winansi_fprintf(__VA_ARGS__) | 153 | #define fprintf(...) winansi_fprintf(__VA_ARGS__) |
154 | 154 | ||
155 | int winansi_get_terminal_width_height(struct winsize *win); | ||
156 | |||
155 | /* | 157 | /* |
156 | * stdlib.h | 158 | * stdlib.h |
157 | */ | 159 | */ |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index a02a504b0..53c48557d 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -256,7 +256,11 @@ int FAST_FUNC get_terminal_width_height(int fd, unsigned *width, unsigned *heigh | |||
256 | win.ws_col = 0; | 256 | win.ws_col = 0; |
257 | /* I've seen ioctl returning 0, but row/col is (still?) 0. | 257 | /* I've seen ioctl returning 0, but row/col is (still?) 0. |
258 | * We treat that as an error too. */ | 258 | * We treat that as an error too. */ |
259 | #if !ENABLE_PLATFORM_MINGW32 | ||
259 | err = ioctl(fd, TIOCGWINSZ, &win) != 0 || win.ws_row == 0; | 260 | err = ioctl(fd, TIOCGWINSZ, &win) != 0 || win.ws_row == 0; |
261 | #else | ||
262 | err = winansi_get_terminal_width_height(&win) == 0; | ||
263 | #endif | ||
260 | if (height) | 264 | if (height) |
261 | *height = wh_helper(win.ws_row, 24, "LINES", &err); | 265 | *height = wh_helper(win.ws_row, 24, "LINES", &err); |
262 | if (width) | 266 | if (width) |
diff --git a/win32/winansi.c b/win32/winansi.c index 3276913da..7730fd006 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -417,3 +417,20 @@ int winansi_printf(const char *format, ...) | |||
417 | 417 | ||
418 | return rv; | 418 | return rv; |
419 | } | 419 | } |
420 | |||
421 | int winansi_get_terminal_width_height(struct winsize *win) | ||
422 | { | ||
423 | BOOL ret; | ||
424 | CONSOLE_SCREEN_BUFFER_INFO sbi; | ||
425 | |||
426 | init(); | ||
427 | |||
428 | win->ws_row = 0; | ||
429 | win->ws_col = 0; | ||
430 | if ((ret=GetConsoleScreenBufferInfo(console, &sbi)) != 0) { | ||
431 | win->ws_row = sbi.srWindow.Bottom - sbi.srWindow.Top + 1; | ||
432 | win->ws_col = sbi.srWindow.Right - sbi.srWindow.Left + 1; | ||
433 | } | ||
434 | |||
435 | return ret; | ||
436 | } | ||