Introduction
WPF Command Prompt is a command line console that comes with a number of features including:
- Save/Load different console settings (or use internal defaults)
- Save/Load different command histories
- Save/Load style themes (or use internal defaults)
- Message area background color, fonts/font sizes/font colors, border size/color and padding size manually or using themes
- Command prompt background color, font/font size/font colors, border size/color and padding size manually or using themes
- Internal or external command parsing
- Command history function
The basic layout has a message area (RichTextBox
) and a command prompt area (TextBox
) in a user control. I kept the command prompt at the bottom of the window as there is a resizing issue I have yet to work out. But, after using it for a while, I find I prefer the command prompt at the bottom of the window anyway. The prompt text (e.g. "C:\MyStuff\>") in the command prompt area is protected for being changed or deleted by the end user.
The message area consists of two areas, the message prompt area and the message text area:
The message prompt area contains the text entered from the command prompt. The message text contains text written to the console.
For brevity, not all properties/methods are shown here. The complete MSDN style documentation for WPFCommandPrompt
can be found at http://cgdn.blogdns.net:8080/. See the project demo for examples of most of the functionality. This project can also be downloaded from my web site at http://codegravy.dyndns.org:8080/.
Background
WPF Command Prompt is the end result of a project I started a few months ago when I needed a console app for a project I was working on.
Using the Code
Creating a new command prompt is as simple as:
using WPFCommandPrompt;
WPFPrompt commandPrompt = new WPFPrompt();
commandPrompt.ReadLine += new ReadLineEventHandler(ProcessCommand);
commandPrompt.Show();
private void ProcessCommand(object sender, ConsoleReadLineEventArgs e)
{
}
public void WriteLine(string output)
{
commandPrompt.WriteLine(output);
}
There are two constructors to choose between:
public WPFPrompt() public WPFPrompt(int styleThemeIndex)
Writing to the console:
public void WriteLine(string output)
public void WriteLine(string output, Brush foreground)
public void WriteLine(Paragraph paragraph)
public void WriteLine(object sender, ConsoleWriteLineEventArgs e)
The following basic properties can be set without creating the console window and can be saved/loaded from disk if not setting or using defaults:
public bool AllowEmptyCommand
public string ConsoleTitle
public string ConsoleVersion
public double DefaultConsoleHeight
public double DefaultConsoleWidth
public string DefaultPrompt
public string Delimiters
public bool EnableCommandHistory
public bool EnableLoadStyleThemes
public bool ManualCommandHistory
public double MaxConsoleHeight
public double MaxConsoleWidth
public double MaxFontSize
public double MinConsoleHeight
public double MinConsoleWidth
public string Prompt
public int StyleThemeIndex
public string WelcomeMessage
public bool UserInternalCommandParsing
Style Themes - Any changes to the theme are not changed in the original theme. Call UpdateStyleTheme()
to copy any changes to the current theme to the original, or CurrentThemeToNew()
to create a new theme from the current theme and any changes. Call SaveStyleThemes()
to save to disk after calling UpdateStyleTheme()
or CurrentThemeToNew()
. Note that the provided style themes look ok but are far from great as I'm far better at making a UI functional than aesthetically pleasing. If anyone creates some nice looking themes, please share them with everyone here!
Points of Interest
Although I think there's far too much code in some of the classes, it works just fine. I'll think about re-doing things later :).
History