拍摄彩色控制台输出到WPF应用程序控制台、应用程序、彩色、WPF

2023-09-03 06:42:44 作者:乖一点就抱你

类似这个问题,除了控制台程序被包装在WPF应用程序生成彩色输出,所以这将是很好,如果我可以捕捉的颜色以及文字。

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.

这是我的第一个WPF程序,我不知道如何去寻找/修改权限控制,目前我只是用一个TextBox它的作品,但仅捕获纯文本。

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.

更新:我试着使用RichTextBox的:

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.

推荐答案

如果我理解你想要正确地做什么,你想屏幕刮旧式的应用程序,在控制台上运行,并得到其控制台输出在控制你的通过WPF应用程序 yourprocess.StandardOutput

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.

中的颜色数据(和格式),将来自控制台将ANSI。这将显示在在控制台重定向文本控制字符的形式,将显示为扩展ASCII字符和数字。您将需要一个ANSI跨preTER控制,早转换成颜色数据。我知道很容易适应存在多个ANSI终端的控制,应该能够 - 这一个在code项目能够处理的ANSI格式,但它是一个完整的ANSI终端设计处理的连接 - 你可能需要的东西,可以替代的code终端部分显示由 yourprocess.StandarOutput.ReadToEnd返回的字符串()

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().

这里是ANSI / VT100控制codeS ,你会需要的,如果你想编写自己的格式。

Here are the ANSI/VT100 control codes that you will need if you want to write your own formatter.

 
精彩推荐