Mercurial > hg > octave-lojdl
changeset 16476:98155e2b6d42
get terminal size on window systems
* lo-sysdep.h, lo-sysdep.cc (w32_terminal_rows, w32_terminal_cols):
New functions.
* cmd-edit.cc (gnu_readline::do_terminal_rows,
gnu_readline::do_terminal_cols): Use them.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 09 Apr 2013 03:17:48 -0400 |
parents | 0696dcc92fc8 |
children | 64727ed135cb |
files | liboctave/system/lo-sysdep.cc liboctave/system/lo-sysdep.h liboctave/util/cmd-edit.cc |
diffstat | 3 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/system/lo-sysdep.cc +++ b/liboctave/system/lo-sysdep.cc @@ -140,6 +140,36 @@ return pid; } +int +w32_terminal_rows (void) +{ + int retval = 0; + + HANDLE console = GetStdHandle (STD_OUTPUT_HANDLE); + + CONSOLE_SCREEN_BUFFER_INFO csbi; + + if (GetConsoleScreenBufferInfo (console, &csbi)) + retval = csbi.dwSize.Y; + + return retval; +} + +int +w32_terminal_cols (void) +{ + int retval = 0; + + HANDLE console = GetStdHandle (STD_OUTPUT_HANDLE); + + CONSOLE_SCREEN_BUFFER_INFO csbi; + + if (GetConsoleScreenBufferInfo (console, &csbi)) + retval = csbi.dwSize.X; + + return retval; +} + void w32_clear_console_window (void) {
--- a/liboctave/system/lo-sysdep.h +++ b/liboctave/system/lo-sysdep.h @@ -36,6 +36,8 @@ extern pid_t octave_popen2 (const std::string&, const string_vector&, bool, int *, std::string&); +extern int w32_terminal_rows (void); +extern int w32_terminal_cols (void); extern void w32_clear_console_window (void); #endif
--- a/liboctave/util/cmd-edit.cc +++ b/liboctave/util/cmd-edit.cc @@ -302,7 +302,11 @@ int gnu_readline::do_terminal_rows (void) { +#if defined (__WIN32__) && ! defined (__CYGWIN__) + int sh = w32_terminal_rows (); +#else int sh = ::octave_rl_screen_height (); +#endif return sh > 0 ? sh : 24; } @@ -310,7 +314,11 @@ int gnu_readline::do_terminal_cols (void) { +#if defined (__WIN32__) && ! defined (__CYGWIN__) + int sw = w32_terminal_cols (); +#else int sw = ::octave_rl_screen_width (); +#endif return sw > 0 ? sw : 80; }