views:

520

answers:

3

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.

A: 

Have you tried looking into RichTextBox instead of TextBox?

viggity
First thing I looked at :) Will update question with example I tried.
Si
A: 

Consider this more of a starting point than an answer. Console Screen Buffers says you can get this information via GetConsoleScreenBufferInfo.

hjb417
+11  A: 

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.

Dale Halliwell
+1 Thanks for that, will look into it. FWIW, it's actually not a legacy app, rather the console is a wrapper around a class library which performs database installs and upgrades. It's just an easy way to parse some tricky variables. We use the console as part of a Wix DTF custom action for installs, and the WPF project is so our developers can easily use the console app as well.
Si