Similar to this question, except the console program being wrapped up in the WPF application produces coloured output, so it would be nice if I could capture the colour as well as the text.
This is my first WPF program and I'm not sure how to go about finding/modifying the right control, currently I'm just using a TextBox which works but only captures plain text.
Update: I tried using RichTextBox:
richTextBox.Document.Blocks.Clear();
richTextBox.Document.Blocks.Add(new Paragraph(new Run(process.StandardOutput.ReadToEnd())));
Alas it only showed plain text.
If I understand what you want to do correctly, you want to screen scrape a legacy app that runs on the console and get its console output in a control in your WPF app via yourprocess.StandardOutput
.
The color data (and formatting) that will come from the console will be ANSI. This will show up in the form of control chars in the redirected console text that will show up as extended ASCII characters and numbers. You will need an ANSI interpreter control to translate that back into color data. I know there exist several ANSI terminal controls that should be able to be adapted easily - this one on the Code Project is able to handle the ANSI formatting, but it is a full ANSI terminal designed to handle a connection - you may need to replace the terminal part of the code with something that can display the string returned by yourprocess.StandarOutput.ReadToEnd()
.
Here are the ANSI/VT100 control codes that you will need if you want to write your own formatter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With