Redirecting stdout to some JUCE GUI Element



I’m using JUCE to develop a scientific application that evolved from a command line tool to a GUI application. It has a lot of prints to stdout, some come from our code and some come from 3rd party libraries. A lot of output could be translated to nice expressive GUI components, but some command line output will still be necessary and useful, so I’d like to implement some kind of component in the GUI that displays all output to stdout and stderr.

I successfully managed to capture stdout and stderr through a pipe, but I’m not sure how to manage to display the text itself? I need something like a label but with the option to push back text at the end and truncate it at the beginning if the text has filled the whole window. Maybe some scrolling-option would be nice. Just like most standard terminals work. Is there any component except for label that could help me to achieve this easily? Any hints are appreciated!


You might want to have a look at how we do it in the demo app’s unit-tests page:


…BTW I should mention that the demo isn’t a good example if you need high performance or have very large amounts of text… If that’s the case you might want to use a CodeEditorComponent or roll your own for it.


Great! Exactly what I was looking for! I’m just wondering if I should bother about memory consumption when the application runs for multiple hours and generates a lot of output? Should I take care of deleting some text at the beginning at some time to avoid eating all my RAM by holding a giant string in memory that holds all output generated until the application started?


Yes, the TextEditor doesn’t scale well to large amounts of text, you’d need to trim its start to keep the overall size low if you use one of those.


I didn’t see your second response mentioning the CodeEditorComponent - didn’t know about this thing. So I managed it with a TextEditor and a StringArray holding all lines of text where I add new lines to the end of the array and delete old lines at the beginning and then rebuild the content of the TextEditorComponent from time to time. That works smooth and fast enough for me.

This is the code, any thoughts on this are appreciated!