dwmkerr / consolecontrol

ConsoleControl is a C# class library that lets you embed a console in a WinForms or WPF application.
MIT License
736 stars 171 forks source link

Handle console foreground and background #4

Open dwmkerr opened 11 years ago

dwmkerr commented 11 years ago

Respect console foreground and background. http://www.codeproject.com/Articles/335909/Embedding-a-Console-in-a-C-Application?msg=4496572

camalot commented 9 years ago

I am not sure how Windows Handles console colors, but I have been doing some work on the the source of ConsoleControl for basically redirecting a shell from linux (Android actually) and added support for how linux handles the coloring. It is done with ^[{arg};{fg};{bg}mCONSOLE_OUTPUT^[0m

{arg} defines things like bold, italic, strike, blink, etc. (I have not implemented that). I am ignoring the arg. {fg} is a value that indicates the forecolor {bg} is a value that indicated the background color.

^[0m indicates the color should go back to "normal".

^[ is [ESCAPE] character 0x1B.

Here is a gist with how I implemented it. Keep in mind there are some other changes too. Like I implemented a command history, and a "fat" caret. But WriteOutput that only takes "output" will parse the content, splitting it on ^[ ("\e") and change the RTB forecolor based on that.

Gist: ConsoleControl.cs

As I said, I don't know how the Windows Console indicates colors, as I don't have a need for those currently, but thought I would share what I did. I know this issue is a bit old, but I figured it couldn't hurt to share it.

dwmkerr commented 9 years ago

@camalot thanks for updating the issue with this info, really appreciate you taking the time to do that! I'll look into this issue again with the extract insight you've given, who knows, I may be able to close it soon!