开发者

Capture coloured console output into WPF application

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 tex开发者_开发知识库t.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜