// Input Keyboard void GameSystem::KeyBoard( unsigned char key, int x, int y ) { std::string lCommandLine( "" ); if( mActivateConsole && ( key != '`' ) && ( key != 13 ) && ( key != 8 ) ) SKCONSOLE.AddCharToCurrentStr( key ); switch( key ) { case 13: // Enter if( mActivateConsole ) lCommandLine = SKCONSOLE.NextLine(); break; case 8: // Back Space if( mActivateConsole ) SKCONSOLE.DeleteCharToCurrentStr(); break; case '`': mActivateConsole = !mActivateConsole; break; } if( mActivateConsole ) { bool lTypeCommand = false; std::vector< std::string > lTokens; // Split String by Space if( lCommandLine[0] == '/' ) { std::stringstream lStrStream( &lCommandLine[1] ); std::string lBuf; lTypeCommand = true; while( lStrStream >> lBuf ) lTokens.push_back( lBuf ); } if( lTypeCommand ) { CommandProcess( lTokens ); } }
void CommandPrompt::execute() { for (;;) { #ifdef ZORBA_HAVE_LIBEDIT_H const char* lBuf; int lCharsRead = -1; lBuf = el_gets(theEditLine, &lCharsRead); std::string lCommandLine(lBuf, lCharsRead - 1); #else bool lWithOutput = true; if (lWithOutput) { std::cout << "(xqdb) "; } lWithOutput = true; std::string lCommandLine; std::getline(std::cin, lCommandLine); if (std::cin.fail()) { lWithOutput = false; std::cin.clear(); continue; } #endif std::vector<std::string> lArgs; // split the command into arguments parseLine(lCommandLine, lArgs); std::string::size_type lSize = lArgs.size(); // empty command? do nothing! if (lSize == 0) { lArgs = theLastArgs; if (lArgs.size() == 0) { continue; } } #ifdef ZORBA_HAVE_LIBEDIT_H else { HistEvent lHistoryEvent; history(theHistory, &lHistoryEvent, H_ENTER, lCommandLine.c_str()); } #endif theLastArgs = lArgs; UntypedCommand* lCommand = NULL; // help is not a command but a hook here if (lArgs.at(0) == "h" || lArgs.at(0) == "help") { std::string lCmd = ""; // if the user needs the help for a specific command if (lSize > 1) { // do nothing if we don't have a command starting with this prefix? // findCommand will print the appropriate errors if (!findCommand(lArgs[1], lCommand)) { continue; } } printHelp(lCommand); continue; } if (findCommand(lArgs[0], lCommand) && lCommand->execute(lArgs)) { return; } continue; } }