Command Line Component


You’re right jules, one a day! :hihi:

This morning’s challenge: old school flavour

This is in two parts, heavily commented and very easy to use.

CommandLineSystem forms a base that defines what the command line can do. CommandLineComponent provides a text output space and a user input field.

Demo: CommandLineTest windows build
Source: CommandLine source & VC++e project

Lots of stuff is done automatically. The system has a startup message, ‘help’ keywords (which display the known commands), an array of known commands, automatic separation of a command from its parameters, the option to keep the command as a single string, optional ignoring of unknown parameters, etc…

A virtual ‘processCommand’ function is called with the command [string], parameters [string array] and the originating CommandLineComponent’s pointer. If you’ve set it to ignore unknown commands, this will only be called for known commands. This is where you define the behaviour of your system.

If you’ve set it to preserve the command string, the splitting into command/parameters is not done, and the command (and the pointer to the component) is passed to the virtual ‘processCommandString’ function.

See the comments for more information.


Obviously it’s probably a bit pointless, but i figured it would be a bit of fun. Plus, loads of apps still have command line interfaces somewhere in them (e.g. matlab, games with a console, etc).

Perhaps it could be used as a kind of ‘interactive debugger’ feature that could be added to release builds (with some kind of access mechanism) which could be used to output registered variable values.

Or maybe a text adventure :hihi:


actually, two days ago this would have saved me a few minutes.

I often knock together 15 minute apps[1], and while most of the time I’ll use perl, lua, or matlab to get myself out of trouble, I might start doing a few more in command lined JUCE.

Typically I avoid command line stuff with windows cos it is a pain to have a Win32 GUI app also sport a command line.

[1] that’s how long they are used for, not how long it takes to write them. :evil: