Possible to export output to a text file?

Skip to first unread message

Samuel Tay

Jun 2, 2017, 9:30:49 PM6/2/17
to Brick Users
I realize this is a terminal for interfaces, but I'm curious if I am only generating static content but leveraging this library for borders, text, ansi color, etc., is it possible to take the result of a drawing and save it to a file? So that you could see the drawing by simply cat brick_result.txt, without even having the program locally?

Jonathan Daugherty

Jun 3, 2017, 11:50:51 AM6/3/17
to Samuel Tay, Brick Users

Brick (and vty) both don't have particular support for this, but even
so, it's possible by redirecting stdout to a file:

$ some_brick_program > screenshot.txt

However, bear in mind that if you do this, the only reliable way to view
the file (e.g. with 'cat') is to do it in the same terminal emulator
that ran the program originally, or at least one that is compatible
enough with it. Otherwise the output might contain control sequences
that were right for the original terminal but that could confuse the
terminal being used to view the contents.

I tried this with one of my programs and I noticed that the terminal
reset done by the application at shutdown makes it appear as if the file
has no content (when emitted with 'cat') but that's because the file
contains both the original screen output as well as a screen-clear. So
for best results, it might be necessary to do something like

1. Run: some_brick_program > screenshot.txt
2. In another shell, while some_brick_program is running but once it
has emitted the desired output, cp screenshot.txt
3. Quit / kill the brick program.

This way, you've captured the output before the screen reset is sent.

Hope that helps!

Jonathan Daugherty

Samuel Tay

Jun 5, 2017, 9:22:57 AM6/5/17
to Brick Users
Gotcha, thanks for the quick response.
Reply all
Reply to author
0 new messages