views:

32

answers:

0

Alright, so, here is the scenario:

I am outputting the result of a console app (in my case, MSBuild) and it has colors. I want to use those colors, or at least some colors, in a RichTextBox on my WPF page. I successfully have it routing the output to the RTB and it works great by adding new inlines. It's fast and efficient.

The problem is that the default output of MSBuild does not have any indication of what color the line should be; no possible regex or StartsWith or something could infer it.

That means I am either stuck using plain black for the output, OR I have the ability to have MSBuild output in valid XML.

I was thinking that since a FlowDocument can be constructed from XamlReader, which in turn can be constructed from a styled XML document, there might be a way to go through that conversion process and output a FlowDocument to the RTB.

I can definitely see this working if I was loading the whole XML file into the RTB.

Where I don't see this working is when I am dealing with line-by-line updates from DataReceivedEventArgs (process redirection). I'll get a line like "" and that's it, so I'd have a workflow like:

  1. Event raised, new line from console detected.
  2. Append new line of XML to running output XML document.
  3. Transform running XML document using XSLT.
  4. Create a new XAML reader from the transformed XML.
  5. Update the RTB FlowDocument property with new XAML.

The problem with this is that it seems a) inefficient and b) not possible as the running XML document will be totally invalid as it will be missing closing tags. But, I am not too familiar with how well transforms work with invalid XML.

Any wisdom from the crowds?

I am about 90% sure I'll just stick with a TextBox and forget about syntax coloring. Seems to be way too much work for something I could just pop up in a command prompt window.