35 #include "../../commands_h.h" 40 , m_currentCommandCursorPosition(0)
41 , m_inEscapeSequence(false)
42 , m_historyEntryToCopyFrom(0)
43 , m_commandHistoryInsertPosition(0)
44 , m_commandHistoryMaxSize(100)
46 m_commandHistory.resize(m_commandHistoryMaxSize,
"");
49 assert(m_GXemul != NULL);
53 #include "../../commands.h" 72 return m_commandHistoryInsertPosition;
74 size_t lastInsertedPosition =
75 (m_commandHistoryInsertPosition - 1 + m_commandHistoryMaxSize)
76 % m_commandHistoryMaxSize;
78 if (m_commandHistory[lastInsertedPosition] == command)
79 return m_commandHistoryInsertPosition;
81 m_commandHistory[m_commandHistoryInsertPosition ++] = command;
82 m_commandHistoryInsertPosition %= m_commandHistoryMaxSize;
84 return m_commandHistoryInsertPosition;
93 int index = (m_commandHistoryInsertPosition - nStepsBack +
94 m_commandHistoryMaxSize) % m_commandHistoryMaxSize;
96 return m_commandHistory[index];
100 bool CommandInterpreter::TabComplete(
string& commandString,
101 size_t& cursorPosition,
bool visibleShowAvailable)
103 string wordToComplete;
104 bool firstWordOnLine =
true;
106 size_t pos = cursorPosition;
109 if (commandString[pos] ==
' ')
111 wordToComplete = commandString[pos] + wordToComplete;
116 if (commandString[pos] !=
' ') {
117 firstWordOnLine =
false;
122 bool completeCommands = firstWordOnLine;
124 if (wordToComplete ==
"") {
125 if (!visibleShowAvailable)
130 if (completeCommands) {
132 vector<string> allCommands;
133 for (Commands::const_iterator it = m_commands.begin();
134 it != m_commands.end(); ++it)
135 allCommands.push_back(it->first);
137 ShowAvailableWords(allCommands);
141 FindPathByPartialMatch(
""));
146 vector<string> matches;
149 FindPathByPartialMatch(wordToComplete,
true);
151 if (completeCommands) {
152 Commands::const_iterator it = m_commands.begin();
153 for (; it != m_commands.end(); ++it) {
154 const string& commandName = it->first;
155 if (commandName.substr(0, wordToComplete.length())
157 matches.push_back(commandName);
162 if (matches.size() == 0)
165 string completedWord;
168 if (matches.size() == 1) {
170 completedWord = matches[0];
173 size_t i, n = matches.size();
174 for (
size_t pos2 = 0; ; pos2 ++) {
175 if (pos2 >= matches[0].length())
178 for (i=1; i<n; i++) {
179 if (matches[i][pos2] != ch)
190 if (visibleShowAvailable)
191 ShowAvailableWords(matches);
195 if (!completedWord.empty()) {
196 cursorPosition -= wordToComplete.length();
197 commandString.erase(cursorPosition, wordToComplete.length());
198 commandString.insert(cursorPosition, completedWord);
199 cursorPosition += completedWord.length();
211 if (matches.size() == 1 && cursorPosition == commandString.length()) {
212 bool isCommand =
false;
213 Commands::const_iterator it = m_commands.begin();
214 for (; it != m_commands.end(); ++it) {
215 const string& commandName = it->first;
216 if (commandName == matches[0]) {
223 commandString +=
" ";
228 return matches.size() == 1;
232 bool CommandInterpreter::TabCompleteWithSubname(
string& commandString,
233 size_t& cursorPosition,
bool visibleShowAvailable)
235 if (cursorPosition == 0)
239 size_t pos = cursorPosition - 1;
241 while (pos > 0 && commandString[pos] !=
'.') {
254 bool success = TabComplete(commandString, pos, visibleShowAvailable);
264 int startOfComponentName = pos;
265 while (startOfComponentName >= 0 &&
266 commandString[startOfComponentName] !=
' ')
267 -- startOfComponentName;
269 if (startOfComponentName < 0)
270 startOfComponentName = 0;
272 string componentName = commandString.substr(startOfComponentName,
273 pos - startOfComponentName);
277 LookupPath(componentName);
279 cursorPosition = pos + nStepsBack;
285 size_t startOfMethodName = pos + 1;
286 size_t methodNameLen = 0;
287 while (startOfMethodName + methodNameLen < cursorPosition &&
288 commandString[startOfMethodName+methodNameLen] !=
' ')
291 string methodName = commandString.substr(startOfMethodName,
296 vector<string> names;
297 vector<string> matchingNames;
301 if (methodName.length() != 0) {
302 for (
size_t i=0; i<names.size(); ++i) {
303 if (names[i].substr(0, methodName.length()) ==
306 matchingNames.push_back(names[i]);
310 matchingNames = names;
313 if (matchingNames.size() == 0)
319 string longestPossibleMatch =
"";
320 size_t i, n = matchingNames.size();
321 for (
size_t pos2 = 0; ; pos2 ++) {
322 if (pos2 >= matchingNames[0].length())
325 for (i=1; i<n; i++) {
326 if (matchingNames[i][pos2] != ch)
330 longestPossibleMatch += ch;
335 commandString.replace(startOfMethodName, methodNameLen,
336 longestPossibleMatch);
337 cursorPosition += longestPossibleMatch.length() - methodNameLen;
340 if (nrOfMatches == 1)
344 if (visibleShowAvailable) {
345 vector<string> allNames;
346 vector<string> matchingNames2;
349 for (
size_t j=0; j<allNames.size(); ++j) {
350 if (methodName.length() == 0 ||
351 allNames[j].substr(0, methodName.length()) == methodName)
352 matchingNames2.push_back(allNames[j]);
355 if (matchingNames2.size() > 0) {
357 ShowAvailableWords(matchingNames2);
360 if (visibleShowAvailable) {
361 vector<string> allNames;
362 vector<string> matchingNames2;
365 for (
size_t j=0; j<allNames.size(); ++j) {
366 if (methodName.length() == 0 ||
367 allNames[j].substr(0, methodName.length()) == methodName)
368 matchingNames2.push_back(allNames[j]);
371 if (matchingNames2.size() > 0) {
373 ShowAvailableWords(matchingNames2);
383 if (m_inEscapeSequence) {
384 m_escapeSequence += key;
389 if (m_escapeSequence ==
"[C") {
390 m_inEscapeSequence =
false;
392 }
else if (m_escapeSequence ==
"[D") {
393 m_inEscapeSequence =
false;
395 }
else if (m_escapeSequence ==
"OH") {
396 m_inEscapeSequence =
false;
398 }
else if (m_escapeSequence ==
"[H") {
399 m_inEscapeSequence =
false;
401 }
else if (m_escapeSequence ==
"OF") {
402 m_inEscapeSequence =
false;
404 }
else if (m_escapeSequence ==
"[F") {
405 m_inEscapeSequence =
false;
407 }
else if (m_escapeSequence ==
"[A") {
408 m_inEscapeSequence =
false;
410 }
else if (m_escapeSequence ==
"[B") {
411 m_inEscapeSequence =
false;
413 }
else if (m_escapeSequence.length() > 2) {
420 m_inEscapeSequence =
false;
434 m_currentCommandCursorPosition = 0;
438 if (m_currentCommandCursorPosition > 0)
439 m_currentCommandCursorPosition --;
443 if (m_currentCommandCursorPosition <
444 m_currentCommandString.length())
445 m_currentCommandString.erase(
446 m_currentCommandCursorPosition, 1);
450 m_currentCommandCursorPosition =
451 m_currentCommandString.length();
455 if (m_currentCommandCursorPosition <
456 m_currentCommandString.length())
457 m_currentCommandCursorPosition ++;
461 ClearCurrentInputLineVisually();
462 m_currentCommandString.resize(m_currentCommandCursorPosition);
466 ClearCurrentInputLineVisually();
468 m_historyEntryToCopyFrom --;
469 if (m_historyEntryToCopyFrom < 0)
470 m_historyEntryToCopyFrom = 0;
472 m_currentCommandString =
474 m_currentCommandCursorPosition =
475 m_currentCommandString.length();
479 ClearCurrentInputLineVisually();
481 m_historyEntryToCopyFrom ++;
482 m_currentCommandString =
486 if (m_currentCommandString ==
"") {
487 m_historyEntryToCopyFrom --;
488 m_currentCommandString =
491 m_currentCommandCursorPosition =
492 m_currentCommandString.length();
501 ClearCurrentInputLineVisually();
504 while (m_currentCommandCursorPosition > 0) {
505 if (m_currentCommandString[
506 m_currentCommandCursorPosition-1] ==
' ') {
507 m_currentCommandCursorPosition --;
508 m_currentCommandString.erase(
509 m_currentCommandCursorPosition, 1);
518 while (m_currentCommandCursorPosition > 0) {
519 if (m_currentCommandString[
520 m_currentCommandCursorPosition-1] !=
' ') {
521 m_currentCommandCursorPosition --;
522 m_currentCommandString.erase(
523 m_currentCommandCursorPosition, 1);
533 if (m_currentCommandCursorPosition > 0) {
534 m_currentCommandCursorPosition --;
535 m_currentCommandString.erase(
536 m_currentCommandCursorPosition, 1);
542 m_inEscapeSequence =
true;
543 m_escapeSequence =
"";
549 bool success = TabComplete(m_currentCommandString,
550 m_currentCommandCursorPosition,
true);
556 TabCompleteWithSubname(m_currentCommandString,
557 m_currentCommandCursorPosition,
true);
567 if (!m_currentCommandString.empty()) {
571 }
else if (m_mayBeReexecuted !=
"") {
580 m_currentCommandString.insert(
581 m_currentCommandCursorPosition, 1, key);
582 m_currentCommandCursorPosition ++;
586 if (key !=
'\n' && key !=
'\r')
590 return key ==
'\n' || key ==
'\r';
594 void CommandInterpreter::ShowAvailableWords(
const vector<string>& words)
598 const size_t n = words.size();
603 for (i=0; i<n; ++i) {
604 size_t len = words[i].length();
612 std::stringstream msg;
614 for (i=0; i<n; ++i) {
618 size_t len = words[i].length();
622 for (
size_t j=len; j<maxLen; j++) {
627 if (lineLen >= 77 - maxLen || i == n-1) {
640 m_currentCommandString, m_currentCommandCursorPosition);
644 void CommandInterpreter::ClearCurrentInputLineVisually()
646 string clearString =
"";
647 clearString.insert((
size_t)0, m_currentCommandString.length(),
' ');
650 clearString, m_currentCommandCursorPosition);
656 m_currentCommandString =
"";
657 m_currentCommandCursorPosition = 0;
658 m_historyEntryToCopyFrom = 0;
662 static void SplitIntoWords(
const string& commandOrig,
663 string& commandName, vector<string>& arguments)
665 string command = commandOrig;
674 int insideParenthesesCount = 0;
675 while (pos < command.length()) {
676 if (command[pos] ==
'(')
677 insideParenthesesCount ++;
678 if (command[pos] ==
')')
679 insideParenthesesCount --;
680 if (command[pos] ==
'=' && insideParenthesesCount == 0) {
681 command.replace(pos, 1,
" = ");
690 while (pos < command.length()) {
692 while (pos < command.length() && command[pos] ==
' ')
695 if (pos >= command.length())
701 while (pos < command.length() && command[pos] !=
' ') {
702 newWord += command[pos];
706 if (commandName.empty())
707 commandName = newWord;
709 arguments.push_back(newWord);
714 void CommandInterpreter::VariableAssignment(
const string& componentPath,
715 const string& variableName,
const string& expression)
718 LookupPath(componentPath);
723 variableName +
"'? (Internal error.)\n");
724 throw std::exception();
737 stringstream changeMessages;
740 string msg = changeMessages.str();
742 msg =
"(No state change.)\n";
748 bool CommandInterpreter::RunComponentMethod(
749 const string& componentPathAndMethod,
const vector<string>& arguments)
756 string componentPath;
763 LookupPath(componentPathAndMethod);
769 string tabcompleted = componentPathAndMethod;
770 size_t tmpLen = tabcompleted.length();
771 if (TabComplete(tabcompleted, tmpLen)) {
773 LookupPath(tabcompleted);
780 if (componentPathAndMethod.find(
".") == string::npos)
783 size_t pos = componentPathAndMethod.find_last_of(
'.');
786 componentPath = componentPathAndMethod.substr(0, pos);
788 LookupPath(componentPath);
789 if (!component.
IsNULL()) {
790 methodName = componentPathAndMethod.substr(pos+1);
795 tabcompleted = componentPath;
796 tmpLen = tabcompleted.length();
797 if (TabComplete(tabcompleted, tmpLen)) {
799 LookupPath(tabcompleted);
800 if (!component.
IsNULL()) {
802 componentPathAndMethod.substr(pos+1);
813 if (methodName.empty()) {
818 vector<string> variableNames;
826 for (i=0; i<variableNames.size(); i++)
827 if (variableNames[i].length() > maxLen)
828 maxLen = variableNames[i].length();
830 for (i=0; i<variableNames.size(); i++) {
831 const string& name = variableNames[i];
832 if (name ==
"name" || name ==
"template")
836 for (
size_t j=name.length(); j<=maxLen; j++)
841 ss <<
"= (unknown?)";
855 vector<string> names;
859 for (
size_t i=0; i<names.size(); ++i) {
860 if (names[i].substr(0, methodName.length()) == methodName) {
862 fullMatch = names[i];
866 if (nrOfMatches == 1) {
871 m_mayBeReexecuted = componentPathAndMethod;
881 for (
size_t i=0; i<names.size(); ++i) {
883 if (names[i] == methodName) {
885 fullMatch = names[i];
890 if (names[i].substr(0, methodName.length()) == methodName) {
892 fullMatch = names[i];
898 if (nrOfMatches == 1) {
899 if (arguments.size() > 0) {
900 if (arguments.size() == 1 ||
901 arguments[0] !=
"=") {
906 "Syntax error. Variable assignment syntax" 907 " is:\n <variable> = <expression>\n");
915 "Unknown variable.\n");
920 for (
size_t i=1; i<arguments.size(); ++i)
921 assignment += arguments[i] +
" ";
923 VariableAssignment(component->
GeneratePath(), fullMatch, assignment);
933 ss <<
" = (unknown variable?)";
945 ss << methodName <<
": ambiguous method or variable name of " 948 ss << methodName <<
": not a method or variable of " 960 vector<string> arguments;
961 SplitIntoWords(command, commandName, arguments);
963 m_mayBeReexecuted =
"";
968 Commands::iterator it = m_commands.find(commandName);
969 if (it == m_commands.end()) {
971 string commandTabCompleted = commandName;
972 size_t tmpCursorPos = commandTabCompleted.length();
973 TabComplete(commandTabCompleted, tmpCursorPos);
976 while (commandTabCompleted.length() > 0 &&
977 commandTabCompleted[commandTabCompleted.length()-1] ==
' ')
978 commandTabCompleted.erase(
979 commandTabCompleted.length() - 1);
982 it = m_commands.find(commandTabCompleted);
983 if (it == m_commands.end()) {
986 if (RunComponentMethod(commandName, arguments))
989 ": unknown command. Type help for help.\n");
994 if (arguments.size() != 0 && (it->second)->GetArgumentFormat() ==
"") {
996 " takes no arguments. Type help " + commandName +
997 " for help on the syntax.\n");
1002 bool success = (it->second)->Execute(*m_GXemul, arguments);
1003 if (pSuccess != NULL)
1004 *pSuccess = success;
1006 if ((it->second)->MayBeReexecutedWithoutArgs())
1007 m_mayBeReexecuted = it->first;
1015 return m_currentCommandString;
1022 #ifdef WITHUNITTESTS 1024 static void Test_CommandInterpreter_AddKey_ReturnValue()
1030 ci.
AddKey(
'a') ==
false);
1033 ci.
AddKey(
'\0') ==
false);
1036 ci.
AddKey(
'\n') ==
true);
1039 ci.
AddKey(
'\r') ==
true);
1042 static void Test_CommandInterpreter_KeyBuffer()
1112 static void Test_CommandInterpreter_KeyBuffer_CursorMovement()
1169 static void Test_CommandInterpreter_KeyBuffer_CtrlK()
1202 static void Test_CommandInterpreter_KeyBuffer_CtrlW()
1264 static void Test_CommandInterpreter_CommandHistory()
1326 DummyCommand2(
int& valueRef)
1327 :
Command(
"dummycommand",
"[args]")
1336 bool Execute(
GXemul& gxemul,
const vector<string>& arguments)
1342 string GetShortDescription()
const 1344 return "A dummy command used for unit testing.";
1347 string GetLongDescription()
const 1349 return "This is just a dummy command used for unit testing.";
1363 DummyCommand3(
int& valueRef)
1364 :
Command(
"dummycmd",
"[args]")
1373 bool Execute(
GXemul& gxemul,
const vector<string>& arguments)
1379 string GetShortDescription()
const 1381 return "A dummy command used for unit testing.";
1384 string GetLongDescription()
const 1386 return "This is just a dummy command used for unit testing.";
1393 static void Test_CommandInterpreter_AddCommand()
1405 " with the same name",
1415 static void Test_CommandInterpreter_TabCompletion_EmptyLine()
1425 static void Test_CommandInterpreter_TabCompletion_FullWord()
1452 " the tab-completed word",
1456 static void Test_CommandInterpreter_TabCompletion_SpacesFirstOnLine()
1475 static void Test_CommandInterpreter_TabCompletion_Partial()
1498 static void Test_CommandInterpreter_TabCompletion_C()
1515 static void Test_CommandInterpreter_TabCompletion_OnlyCommandAsFirstWord()
1543 static void Test_CommandInterpreter_TabCompletion_ComponentName()
1562 static void Test_CommandInterpreter_TabCompletion_ComponentNameAlreadyComplete()
1582 static void Test_CommandInterpreter_TabCompletion_ComponentNameMultiple()
1595 UnitTest::Assert(
"there are both cpu0 and cpu1, so don't expand all the way",
1601 static void Test_CommandInterpreter_TabCompletion_ComponentNameMultipleParents()
1620 static void Test_CommandInterpreter_TabCompletion_ComponentNameNonexist()
1640 static void Test_CommandInterpreter_TabCompletion_ComponentNameAsArgument()
1672 static void Test_CommandInterpreter_TabCompletion_CWithComponents()
1691 static void Test_CommandInterpreter_TabCompletion_roWithComponents()
1711 static void Test_CommandInterpreter_TabCompletion_ComponentMethods_Empty()
1727 static void Test_CommandInterpreter_TabCompletion_ComponentMethods()
1744 static void Test_CommandInterpreter_TabCompletion_ComponentMethods_Middle()
1769 static void Test_CommandInterpreter_TabCompletion_ComponentMethods_Arg()
1796 static void Test_CommandInterpreter_TabCompletion_ComponentVariables()
1809 UnitTest::Assert(
"tab completion should have caused expansion cpu -> cpu0",
1813 static void Test_CommandInterpreter_TabCompletion_ComponentVariables_Max()
1829 UnitTest::Assert(
"tab completion should have caused expansion ram -> ram0",
1833 static void Test_CommandInterpreter_TabCompletion_ComponentVariables_Max2()
1853 UnitTest::Assert(
"tab completion should have caused expansion ram -> ram0",
1861 static void Test_CommandInterpreter_NonExistingCommand()
1867 ci.
RunCommand(
"nonexistingcommand") ==
false);
1870 static void Test_CommandInterpreter_SimpleCommand()
1882 static void Test_CommandInterpreter_SimpleCommand_NoArgsAllowed()
1891 " fail when attempt is made to execute it with arguments",
1895 static void Test_CommandInterpreter_ComponentMethods()
1912 ci.
RunCommand(
"root.machine0.mainbus0.cpu") ==
true);
1914 ci.
RunCommand(
"root.machine0.mainbus0.cpu0") ==
true);
1916 ci.
RunCommand(
"root.machine0.mainbus0.cpu.u") ==
true);
1918 ci.
RunCommand(
"root.machine0.mainbus0.cpu0.unassemble") ==
true);
1921 static void Test_CommandInterpreter_ComponentVariables_NoArgs()
1934 ci.
RunCommand(
"root.machine0.mainbus0.cpu0.g") ==
true);
1937 static void Test_CommandInterpreter_ComponentVariables_Ambiguous()
1945 UnitTest::Assert(
"cpu.t should not work, there should be multiple matches",
1949 static void Test_CommandInterpreter_ComponentVariables_PartialIsOk()
1967 UNITTEST(Test_CommandInterpreter_AddKey_ReturnValue);
1968 UNITTEST(Test_CommandInterpreter_KeyBuffer);
1969 UNITTEST(Test_CommandInterpreter_KeyBuffer_CursorMovement);
1970 UNITTEST(Test_CommandInterpreter_KeyBuffer_CtrlK);
1971 UNITTEST(Test_CommandInterpreter_KeyBuffer_CtrlW);
1974 UNITTEST(Test_CommandInterpreter_CommandHistory);
1977 UNITTEST(Test_CommandInterpreter_AddCommand);
1980 UNITTEST(Test_CommandInterpreter_TabCompletion_EmptyLine);
1981 UNITTEST(Test_CommandInterpreter_TabCompletion_FullWord);
1982 UNITTEST(Test_CommandInterpreter_TabCompletion_SpacesFirstOnLine);
1983 UNITTEST(Test_CommandInterpreter_TabCompletion_Partial);
1984 UNITTEST(Test_CommandInterpreter_TabCompletion_C);
1985 UNITTEST(Test_CommandInterpreter_TabCompletion_OnlyCommandAsFirstWord);
1986 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentName);
1987 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentNameAlreadyComplete);
1988 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentNameMultiple);
1989 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentNameMultipleParents);
1990 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentNameNonexist);
1991 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentNameAsArgument);
1992 UNITTEST(Test_CommandInterpreter_TabCompletion_CWithComponents);
1993 UNITTEST(Test_CommandInterpreter_TabCompletion_roWithComponents);
1994 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentMethods_Empty);
1995 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentMethods);
1996 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentMethods_Middle);
1997 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentMethods_Arg);
1998 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentVariables);
1999 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentVariables_Max);
2000 UNITTEST(Test_CommandInterpreter_TabCompletion_ComponentVariables_Max2);
2003 UNITTEST(Test_CommandInterpreter_NonExistingCommand);
2004 UNITTEST(Test_CommandInterpreter_SimpleCommand);
2005 UNITTEST(Test_CommandInterpreter_SimpleCommand_NoArgsAllowed);
2006 UNITTEST(Test_CommandInterpreter_ComponentMethods);
2007 UNITTEST(Test_CommandInterpreter_ComponentVariables_NoArgs);
2008 UNITTEST(Test_CommandInterpreter_ComponentVariables_Ambiguous);
2009 UNITTEST(Test_CommandInterpreter_ComponentVariables_PartialIsOk);
void ClearCurrentCommandBuffer()
Clears the current command buffer.
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
StateVariable * GetVariable(const string &name)
Gets a pointer to a state variable.
virtual bool MethodMayBeReexecutedWithoutArgs(const string &methodName) const
Returns whether a method name may be re-executed without args.
const string & GetCurrentCommandBuffer() const
Retrieves the current command buffer.
const refcount_ptr< Component > LightClone() const
Makes a light clone of the component and all its children.
string GeneratePath() const
Generates a string representation of the path to the Component.
const Commands & GetCommands() const
Gets a collection of all commands.
bool RunCommand(const string &command, bool *pSuccess=NULL)
Runs a command, given as a string.
virtual void ExecuteMethod(GXemul *gxemul, const string &methodName, const vector< string > &arguments)
Executes a method on the component.
void AddCommand(refcount_ptr< Command > command)
Adds a new Command to the command interpreter.
void DetectChanges(const refcount_ptr< Component > &oldClone, ostream &changeMessages) const
Compare an older clone to the current tree, to find changes.
An interactive command interpreter, which run Commands.
virtual void ShowCommandMessage(const string &command)=0
Shows a command being executed.
#define UNITTESTS(class)
Helper for unit test case execution.
CommandInterpreter & GetCommandInterpreter()
Gets a reference to the CommandInterpreter.
void GetVariableNames(vector< string > &names) const
Retrieves a component's state variable names.
const string & GetCommandName() const
Gets the name of the command.
string GetHistoryLine(int nStepsBack) const
Retrieves a line from the command history.
string ToString() const
Returns the variable as a readable string.
virtual void GetMethodNames(vector< string > &names) const
Retrieves a component's implemented method names.
bool AddKey(stringchar key)
Adds a character (keypress) to the current command buffer.
int AddLineToCommandHistory(const string &command)
Adds a command line to the command history.
void ReshowCurrentCommandBuffer()
Re-displays the current command buffer.
CommandInterpreter(GXemul *owner)
Constructs a CommandInterpreter.
StateVariables make up the persistent state of Component objects.
A Command is a named function, executed by the CommandInterpreter.
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
A Command which prints the version of the application.
bool SetVariableValue(const string &name, const string &expression)
Sets a variable to a new value.
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
map< string, refcount_ptr< Command > > Commands
UI * GetUI()
Gets a pointer to the GXemul instance' active UI.
virtual void InputLineDone()=0
Executed by the CommandInterpreter when a line has been completed (with a newline).
virtual void RedisplayInputLine(const string &inputline, size_t cursorPosition)=0
Redisplays the interactive command input line.
string GenerateTreeDump(const string &branchTemplate, bool htmlLinksForClassNames=false, string prefixForComponentUrls="") const
Generates an ASCII tree dump of a component tree.
#define UNITTEST(functionname)
Helper for unit test case execution.
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.