An interactive command interpreter, which run Commands. More...
#include <CommandInterpreter.h>
Public Member Functions | |
CommandInterpreter (GXemul *owner) | |
Constructs a CommandInterpreter. More... | |
bool | AddKey (stringchar key) |
Adds a character (keypress) to the current command buffer. More... | |
void | ClearCurrentCommandBuffer () |
Clears the current command buffer. More... | |
void | ReshowCurrentCommandBuffer () |
Re-displays the current command buffer. More... | |
bool | RunCommand (const string &command, bool *pSuccess=NULL) |
Runs a command, given as a string. More... | |
const string & | GetCurrentCommandBuffer () const |
Retrieves the current command buffer. More... | |
void | AddCommand (refcount_ptr< Command > command) |
Adds a new Command to the command interpreter. More... | |
const Commands & | GetCommands () const |
Gets a collection of all commands. More... | |
int | AddLineToCommandHistory (const string &command) |
Adds a command line to the command history. More... | |
string | GetHistoryLine (int nStepsBack) const |
Retrieves a line from the command history. More... | |
Static Public Member Functions | |
static void | RunUnitTests (int &nSucceeded, int &nFailures) |
![]() | |
static void | RunUnitTests (int &nSucceeded, int &nFailures) |
Runs unit test cases. More... | |
An interactive command interpreter, which run Commands.
A command interpreter can execute commands in the form of complete strings, or it can be given one character (keypress) at a time to build up a command. When given individual keypresses, the command interpreter echoes back what is to be printed. It also supports TAB completion.
Definition at line 48 of file CommandInterpreter.h.
CommandInterpreter::CommandInterpreter | ( | GXemul * | owner | ) |
Constructs a CommandInterpreter.
owner | the GXemul instance that owns the CommandInterpreter |
Definition at line 38 of file CommandInterpreter.cc.
void CommandInterpreter::AddCommand | ( | refcount_ptr< Command > | command | ) |
Adds a new Command to the command interpreter.
command | A reference counter pointer to the Command. |
Definition at line 57 of file CommandInterpreter.cc.
References Command::GetCommandName().
Referenced by GetCurrentCommandBuffer().
bool CommandInterpreter::AddKey | ( | stringchar | key | ) |
Adds a character (keypress) to the current command buffer.
Most normal keys are added at the end of the buffer. Some exceptions are:
key | the character/key to add |
Definition at line 381 of file CommandInterpreter.cc.
References AddLineToCommandHistory(), ClearCurrentCommandBuffer(), GetHistoryLine(), GXemul::GetUI(), UI::InputLineDone(), ReshowCurrentCommandBuffer(), RunCommand(), and UI::ShowDebugMessage().
Referenced by GetCurrentCommandBuffer().
int CommandInterpreter::AddLineToCommandHistory | ( | const string & | command | ) |
Adds a command line to the command history.
If the command is empty, or the same as the last command in the command history, it is ignored.
The command history buffer only holds a small fixed number of entries.
command | The command line to add to the command history. |
Definition at line 69 of file CommandInterpreter.cc.
Referenced by AddKey(), and GetCurrentCommandBuffer().
void CommandInterpreter::ClearCurrentCommandBuffer | ( | ) |
Clears the current command buffer.
Definition at line 654 of file CommandInterpreter.cc.
Referenced by AddKey(), and ConsoleUI_SIGINT_Handler().
const Commands & CommandInterpreter::GetCommands | ( | ) | const |
Gets a collection of all commands.
Definition at line 63 of file CommandInterpreter.cc.
Referenced by HelpCommand::Execute(), and GetCurrentCommandBuffer().
const string & CommandInterpreter::GetCurrentCommandBuffer | ( | ) | const |
Retrieves the current command buffer.
Definition at line 1013 of file CommandInterpreter.cc.
References AddCommand(), AddKey(), AddLineToCommandHistory(), UnitTest::Assert(), GXemul::GetCommandInterpreter(), GetCommands(), GetCurrentCommandBuffer(), GetHistoryLine(), RunCommand(), UNITTEST, and UNITTESTS.
Referenced by GetCurrentCommandBuffer().
string CommandInterpreter::GetHistoryLine | ( | int | nStepsBack | ) | const |
Retrieves a line from the command history.
nStepsBack | The number of steps back into the history. 0 means return an empty line, 1 means the last history line, 2 means the second last, and so on. |
Definition at line 88 of file CommandInterpreter.cc.
References Component::GetMethodNames(), GXemul::GetRootComponent(), GXemul::GetUI(), Component::GetVariableNames(), refcount_ptr< T >::IsNULL(), and UI::ShowDebugMessage().
Referenced by AddKey(), and GetCurrentCommandBuffer().
void CommandInterpreter::ReshowCurrentCommandBuffer | ( | ) |
Re-displays the current command buffer.
Useful e.g. when running in text console mode, and the user has pressed CTRL-Z. When returning to GXemul, the current command buffer can be showed again by calling this function.
Definition at line 637 of file CommandInterpreter.cc.
References GXemul::GetUI(), and UI::RedisplayInputLine().
Referenced by AddKey().
bool CommandInterpreter::RunCommand | ( | const string & | command, |
bool * | pSuccess = NULL |
||
) |
Runs a command, given as a string.
The return value from the function is true if the command was run. However, the command may run and fail, and that's what pSuccess is for.
command | the command to run |
pSuccess | a pointer to a bool, which (if pSuccess is non-NULL) will be set to whether the command succeeded or not. |
Definition at line 957 of file CommandInterpreter.cc.
Referenced by AddKey(), DYNTRANS_INSTR(), DummyComponent::GetAttribute(), GetCurrentCommandBuffer(), CopyComponentCommand::GetLongDescription(), MoveComponentCommand::GetLongDescription(), BackwardStepCommand::GetLongDescription(), GXemul::Reset(), MainbusComponent::WriteData(), and CPUComponent::WriteData().
|
static |