changeset 27159:25d0c4b5a3aa

allow terminal_size function to set screen size * pager.cc (Fterminal_size): If argument is a 2-element array, set screen size and return previous size.
author John W. Eaton <jwe@octave.org>
date Fri, 07 Jun 2019 13:29:41 -0400
parents af1015a3d558
children 6b0c61a5a0f0
files libinterp/corefcn/pager.cc
diffstat 1 files changed, 28 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/pager.cc	Fri Jun 07 13:28:09 2019 -0400
+++ b/libinterp/corefcn/pager.cc	Fri Jun 07 13:29:41 2019 -0400
@@ -608,19 +608,44 @@
   return ovl ();
 }
 
-DEFUN (terminal_size, , ,
+DEFUN (terminal_size, args, ,
        doc: /* -*- texinfo -*-
 @deftypefn {} {} terminal_size ()
-Return a two-element row vector containing the current size of the terminal
-window in characters (rows and columns).
+Query or set the size of the terminal window.  If called with no
+arguments, return a two-element row vector containing the current size
+of the terminal window in characters (rows and columns).  If called with
+a two-element vector of integer values, set the terminal size and return
+the previous setting.  Setting the size manually should not be needed
+when using readline for command-line editing.
 @seealso{list_in_columns}
 @end deftypefn */)
 {
+  int nargin = args.length ();
+
+  if (nargin > 1)
+    print_usage ();
+
   RowVector size (2, 0.0);
 
   size(0) = octave::command_editor::terminal_rows ();
   size(1) = octave::command_editor::terminal_cols ();
 
+  if (nargin == 1)
+    {
+      Matrix m = args(0).xmatrix_value ("argument must be a 2-element array");
+
+      if (m.numel () != 2)
+        error ("terminal_size: argument must be a 2-element array");
+
+      int rows = octave::math::x_nint (m(0));
+      int cols = octave::math::x_nint (m(1));
+
+      if (rows <= 0 || cols <= 0)
+        error ("terminal_size: rows and columns must be positive integers");
+
+      octave::command_editor::set_screen_size (rows, cols);
+    }
+
   return ovl (size);
 }