changeset 16477:0696dcc92fc8

allow windows console to be cleared * lo-sysdep.h, lo-sysdep.cc (w32_clear_console_window): New function. * cmd-edit.cc (gnu_readline::do_clear_screen): Use it. * oct-rl-edit.c (octave_rl_clear_screen): Don't call system ("cls"). to clear screen on windows systems.
author John W. Eaton <jwe@octave.org>
date Tue, 09 Apr 2013 03:08:18 -0400
parents 720fd1ca04ec
children 98155e2b6d42
files liboctave/system/lo-sysdep.cc liboctave/system/lo-sysdep.h liboctave/util/cmd-edit.cc liboctave/util/oct-rl-edit.c
diffstat 4 files changed, 41 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/system/lo-sysdep.cc
+++ b/liboctave/system/lo-sysdep.cc
@@ -140,4 +140,37 @@
   return pid;
 }
 
+void
+w32_clear_console_window (void)
+{
+  HANDLE console = GetStdHandle (STD_OUTPUT_HANDLE);
+
+  // Get the number of character cells in the current buffer.
+
+  CONSOLE_SCREEN_BUFFER_INFO csbi; 
+
+  if (GetConsoleScreenBufferInfo (console, &csbi))
+    {
+      DWORD screen_size = csbi.dwSize.X * csbi.dwSize.Y;
+
+      // Fill the entire screen with blanks.
+
+      COORD home = { 0, 0 };
+      DWORD nchars;
+
+      if (FillConsoleOutputCharacter (console, static_cast<TCHAR> (' '),
+                                      screen_size, home, &nchars))
+        {
+          if (GetConsoleScreenBufferInfo (console, &csbi))
+            {
+              if (FillConsoleOutputAttribute (console, csbi.wAttributes,
+                                              screen_size, home, &nchars))
+                {
+                  SetConsoleCursorPosition (console, home);
+                }
+            }
+        }
+    }
+}
+
 #endif
--- a/liboctave/system/lo-sysdep.h
+++ b/liboctave/system/lo-sysdep.h
@@ -35,6 +35,9 @@
 #if defined (__WIN32__) && ! defined (__CYGWIN__)
 extern pid_t octave_popen2 (const std::string&, const string_vector&,
     bool, int *, std::string&);
+
+extern void w32_clear_console_window (void);
+
 #endif
 
 #endif
--- a/liboctave/util/cmd-edit.cc
+++ b/liboctave/util/cmd-edit.cc
@@ -38,6 +38,7 @@
 #include "cmd-hist.h"
 #include "file-ops.h"
 #include "lo-error.h"
+#include "lo-sysdep.h"
 #include "lo-utils.h"
 #include "oct-env.h"
 #include "oct-mutex.h"
@@ -317,7 +318,11 @@
 void
 gnu_readline::do_clear_screen (void)
 {
+#if defined (__WIN32__) && ! defined (__CYGWIN__)
+  w32_clear_console_window ();
+#else
   ::octave_rl_clear_screen ();
+#endif
 }
 
 void
--- a/liboctave/util/oct-rl-edit.c
+++ b/liboctave/util/oct-rl-edit.c
@@ -93,15 +93,6 @@
 void
 octave_rl_clear_screen (void)
 {
-  /* This is a bit of a kluge, but I think it will work (I know, famous
-     last words).  */
-
-#if defined (__WIN32__) && ! defined (__CYGWIN__)
-
-  system ("cls");
-
-#else
-
   int ignore1 = 0;
   int ignore2 = 0;
 
@@ -111,8 +102,6 @@
   rl_clear_screen (ignore1, ignore2);
 
   rl_redisplay_function = saved_redisplay_function;
-
-#endif
 }
 
 void