I'd like some tips-in-the-right-direction or even ready solutions to this problem and I'm pretty stuck (I'm just beginner/intermediate):
I'm trying to implement a SSH in my application. The SSH-backend works fine and such, but I'm stuck at the frontend. What WPF-Combination would present me with an adequate solution to emulate a console? Put aside a complete terminal-emulation, I'd be happy to simply readline/writeline into something that looks like a console :-)
My best approach yet was a 80x50 Grid of single characters resulting in 4000 single cells and that feels like a total overkill.
Another idea was to make a console-Appl. bound to a wpf-window in another project. But...is that even possible and how?
I haven't done it myself, however it is one of my "I'll do it if I have time"-projects. Thus I am still looking for an existing implementation :-P
Anyways some thoughts:
The applroach to use Visuals (i.e. Ellipses, Textblocks) is probably not a good Idea. Just think of what has to happen if you want like 200x100 characters. Maybe even a backbuffer. Holding it all in memory + drawing it....it will be incredibly slow.
Therefore the better (or even right) approach is to "draw yourself". Since WPF is backbuffered and you don't want to display an arbitrary bitmap the most likly approach would be to create a new UserControl and override it's Paint-Method. You ma prefer to derive from Control, but UserControl may have Content, so you can show something like a connection indicator icon inside.
Architecture-wise I'd suggest to create a dependecy property Buffer (
ConsoleBuffer
) that holds the console buffer-model. Another DP would hold the top-left positon Location (long
). It determines where to start the display (while you have a look behind). The console model I would make a class that contains achar[]
and aColor[]
(one dimensional). Use line breaking and\n
characters to make lines (because this is the character of a console). Then if you resize the control it will re-flow without the buffer needing to be re-allocated. You can work with **ConsoleBuffer**s of different sizes (for a different number of look behind characters).ConsoleBuffer.Write(string s)
is your method to do stuff.Maybe it is advisable to hold arrays of arrays
char[][]
to represent lines.... but that is up to finding out while programming.Given that you want to emulate a console, I'd do it like this. Note that you'd have to handle the commands and outputting the results yourself.
page.xaml
page.xaml.cs
Did you know that you can display a Console window from your application by using AllocConsole?
Or you can use this:
For better looks, replace the TextBlock with a ListBox and style the ItemTemplate accordingly.