26 #if defined (HAVE_CONFIG_H)
58 pager_event_handler (pid_t pid,
int status)
69 std::cerr <<
"warning: connection to external pager lost (pid = "
70 << pid <<
')' << std::endl;
71 std::cerr <<
"warning: flushing pending output (please wait)"
87 more_than_a_screenful (
const char *s,
int len)
97 int chars_this_line = 0;
99 for (
int i = 0; i <
len; i++)
103 count += chars_this_line / cols + 1;
110 if (count > available_rows)
120 std::string pager_binary = sys::env::getenv (
"PAGER");
122 if (pager_binary.empty ())
133 char *buf = pbase ();
135 int len = pptr () - buf;
137 if (output_sys.
sync (buf,
len))
141 seekoff (0, std::ios::beg);
150 char *buf = pbase () + m_diary_skip;
152 std::size_t
len = pptr () - buf;
162 m_diary_skip = pptr () - pbase ();
174 char *buf = pbase ();
176 int len = pptr () - buf;
179 external_diary_file.write (buf,
len);
182 seekoff (0, std::ios::beg);
276 : m_interpreter (interp), m_pager_stream (), m_diary_stream (),
277 m_external_pager (nullptr), m_external_diary_file (),
279 m_PAGER_FLAGS (), m_page_output_immediately (false),
280 m_page_screen_output (false), m_write_to_diary_file (false),
281 m_really_flush_to_pager (false), m_flushing_output_to_pager (false)
296 "PAGER_FLAGS",
false);
304 "page_output_immediately");
312 "page_screen_output");
318 std::string cmd = m_PAGER;
320 if (! (cmd.empty () || m_PAGER_FLAGS.empty ()))
321 cmd +=
' ' + m_PAGER_FLAGS;
331 m_pager_stream.
reset ();
332 m_diary_stream.
reset ();
338 if (! m_flushing_output_to_pager)
343 m_really_flush_to_pager =
true;
344 m_flushing_output_to_pager =
true;
346 std::ostream& pager_ostream = m_pager_stream.
stream ();
348 pager_ostream.flush ();
370 if (m_external_diary_file.is_open ())
373 m_external_diary_file.close ();
387 m_external_diary_file.open (m_diary_file_name.c_str (), std::ios::app);
389 if (! m_external_diary_file)
390 error (
"diary: can't open diary file '%s'", m_diary_file_name.c_str ());
401 || m_really_flush_to_pager
402 || (m_page_screen_output && m_page_output_immediately)
403 || ! m_page_screen_output)
408 || ! m_page_screen_output
409 || (m_really_flush_to_pager
410 && m_page_screen_output
411 && ! m_page_output_immediately
412 && ! more_than_a_screenful (buf,
len)));
416 do_sync (buf,
len, bypass_pager);
428 if (m_external_pager)
434 delete m_external_pager;
435 m_external_pager =
nullptr;
440 output_system::start_external_pager ()
442 if (m_external_pager)
454 pager_event_handler);
459 output_system::do_sync (
const char *msg,
int len,
bool bypass_pager)
473 std::cout.write (msg,
len);
479 start_external_pager ();
481 if (m_external_pager)
483 if (m_external_pager->good ())
485 m_external_pager->write (msg,
len);
487 m_external_pager->flush ();
491 m_external_pager->setstate (std::ios::failbit);
504 std::cout.write (msg,
len);
561 int nargin = args.length ();
585 std::string arg = args(0).xstring_value (
"diary: argument must be a string");
592 else if (arg ==
"off")
621 int nargin = args.length ();
630 std::string arg = args(0).xstring_value (R
"(more: argument must be string "on" or "off")");
634 else if (arg ==
"off")
637 error (R
"(more: argument must be "on" or "off")");
645 DEFUN (terminal_size, args, ,
658 int nargin = args.length ();
670 Matrix m = args(0).xmatrix_value (
"argument must be a 2-element array");
673 error (
"terminal_size: argument must be a 2-element array");
678 if (rows <= 0 || cols <= 0)
679 error (
"terminal_size: rows and columns must be positive integers");
687 DEFMETHOD (page_output_immediately, interp, args, nargout,
711 DEFMETHOD (page_screen_output, interp, args, nargout,
755 return output_sys.
PAGER (args, nargout);
758 DEFMETHOD (PAGER_FLAGS, interp, args, nargout,
777 OCTAVE_END_NAMESPACE(
octave)
static bool forced_interactive()
void insert(pid_t pid, child::child_event_handler f)
static int terminal_rows()
static void set_screen_size(int ht, int wd)
static int terminal_cols()
Provides threadsafe access to octave.
bool interpreter_output(const std::string &msg)
event_manager & get_event_manager()
child_list & get_child_list()
std::string PAGER_FLAGS() const
bool page_screen_output() const
bool page_output_immediately() const
std::string diary_file_name() const
std::ofstream & external_diary_file()
octave_value page_screen_output(const octave_value_list &args, int nargout)
octave_value PAGER_FLAGS(const octave_value_list &args, int nargout)
bool sync(const char *msg, int len)
void clear_external_pager()
std::ostream & __stdout__()
output_system(interpreter &interp)
octave_value PAGER(const octave_value_list &args, int nargout)
bool write_to_diary_file() const
std::string pager_command() const
std::ostream & __diary__()
std::string PAGER() const
octave_value page_output_immediately(const octave_value_list &args, int nargout)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string default_pager()
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void() error(const char *fmt,...)
output_system & __get_output_system__()
std::ofstream ofstream(const std::string &filename, const std::ios::openmode mode)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
bool wifexited(int status)
bool wifsignaled(int status)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.