0

Our application can generate some fairly long report files interactively. We use C++ to generate all the output, but redirected through a TCL console and TCL channel so we can take advantage of output logging etc.

Is there any common way to support paging of output in C++. I've casted around but can't find anything.

Best

Sam

  • 1
    Use your systems existing pager. http://en.wikipedia.org/wiki/Less_%28Unix%29 – Captain Giraffe Mar 07 '15 at 20:53
  • If on Linux, you might be interested by [ncurses](https://www.gnu.org/software/ncurses/ncurses.html), but I am not sure what you really want. – Basile Starynkevitch Mar 07 '15 at 21:00
  • More specifically....@DonalFellows 1. we generate output from C++ by writing to a Tcl_Channel - so that we can merge the output of C++ with anything generated by TCL for both console and output logging. The paging is restricted to a single "command" that the user runs. 2. C++ or TCL doesn't matter to me. Just has to work. 3. our application is completely linux based. 4. On system pagers like "more" and "less" - I don't have a good idea of how to do that in the C++/Tcl environment where output is being generated primarily from C++ but printed to the console via a Tcl_Channel. sam – Sam Appleton Mar 07 '15 at 22:26

1 Answers1

0

OK, so the situation is that you're writing to a Tcl_Channel that a Tcl interpreter is also writing to. That should work. The simplest way to put paging on top of that is to make that channel be one of the standard channels (I'd pick stdout) and feed the whole lot through a pager program like more or less. That'll only take you a few seconds to get working.

Otherwise, it's possible to write a channel in Tcl 8.5 using just Tcl code; that's what a reflected channel is (that's the Tcl 8.6 documentation, but it works the same way in 8.5). However, using that to do a pager is going to be quite a lot of work; channels work with bytes not characters. It's probably also possible to do it using a stacked channel transformation (8.6 only).

However, if sending the output to a Tk text widget is acceptable (I know it isn't precisely what you asked for…) there's already a package in Tcllib for it.

package require Tk
package require tcl::chan::textwindow

pack [text .t]
set channel [tcl::chan::textwindow .t]

puts $channel "This is a simple test."

That (write-only) channel will work fine if you pass it to your C++ code to use. (You can inspect the source to see how it is done if you wish; the code is pretty short.)

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215