I\'m pondering creating a WPF or Silverlight app that acts just like a terminal window. Except, since it is in WPF/Silverlight, it will be able to \'enhance\' the terminal e
Well, to report my status, I have determined that this is not really feasible with WPF or Silverlight.
The problem with the proposed approach is that there are 80*24 TextBlocks plus some other elements, with multiple bindings for forecolor, backcolor, etc. When the screen needs to scroll, each of these bindings must be re-evaluated, and its very, very slow. Updating the entire screen takes a few seconds. In my app that's not acceptable, the screen is going to be scrolling constantly.
I tried lots of different things to optimize it. I tried using one textblock with 80 runs each per row. I tried batching the change notifications. I tried making it so a 'scroll' event manually updated each textblock. Nothing really helps -- the slow part is updating the UI, not the way it is done.
One thing that would have helped is if I devised a mechanism not to have a textblock or run for every cell, but to only change textblocks when the style of the text changes. So a string of same-color-text for example would be only 1 textblock. However, that would be very complicated, and in the end, it would only help scenarios that have little style variation on the screen. My app is going to have lots of colors flying by (think ANSI art), so it would still be slow in that case.
Another thing I thought would help is if I didn't update the textblocks, but rather scrolled them up as the screen scrolled. So textblocks would be moving from the top to the bottom and then only the new ones would need updating. I managed to get that working by using an observable collection. It helped, but its STILL WAY TOO SLOW!
I even considered a custom WPF control using OnRender. I created one that used drawingContext.RenderText in various ways to see how fast it could be. But EVEN THAT is too darn slow to handle constantly updating the screen.
So that's that .. I've given up on this design. I am instead looking at using an actual Console Window as described here:
No output to console from a WPF application?
I don't really like that since the window is separate from the main window though, so I'm looking for a way to embed the console window in the WPF window, if that's even possible. I'll be asking another SO question on that and will link it here when I do.
UPDATE: Embedding the console window failed, too, because it doesn't take kindly to having its title bar removed. I've implemented it as a low level painting custom WinForms control, and I'm hosting that in WPF. That works beautifully and after some optimizations, its very very fast.