diff options
Diffstat (limited to 'src/console')
| -rw-r--r-- | src/console/ConsoleController.cpp | 49 | ||||
| -rw-r--r-- | src/console/ConsoleController.h | 5 | ||||
| -rw-r--r-- | src/console/ConsoleView.cpp | 9 |
3 files changed, 23 insertions, 40 deletions
diff --git a/src/console/ConsoleController.cpp b/src/console/ConsoleController.cpp index cf4cdcd..7f1975d 100644 --- a/src/console/ConsoleController.cpp +++ b/src/console/ConsoleController.cpp @@ -8,7 +8,7 @@ #include <stack> #include "ConsoleController.h" -ConsoleController::ConsoleController(ControllerCallback * callback): +ConsoleController::ConsoleController(ControllerCallback * callback, CommandInterface * commandInterface): HasDone(false) { consoleModel = new ConsoleModel(); @@ -17,55 +17,28 @@ ConsoleController::ConsoleController(ControllerCallback * callback): consoleModel->AddObserver(consoleView); this->callback = callback; + this->commandInterface = commandInterface; } void ConsoleController::EvaluateCommand(std::string command) { + int returnCode = commandInterface->Command(command); if(command.length()) - consoleModel->AddLastCommand(ConsoleCommand(command, -1, "Syntax error")); + consoleModel->AddLastCommand(ConsoleCommand(command, returnCode, commandInterface->GetLastError())); else if(ui::Engine::Ref().GetWindow() == consoleView) ui::Engine::Ref().CloseWindow(); } +void ConsoleController::CloseConsole() +{ + if(ui::Engine::Ref().GetWindow() == consoleView) + ui::Engine::Ref().CloseWindow(); +} + std::string ConsoleController::FormatCommand(std::string command) { - char * rawText = (char*)command.c_str(); - char * outputData = (char *)calloc(command.length()*6, 1); - int rawTextLoc = 0; - int outputDataLoc = 0; - std::stack<char> pstack; - while(rawText[rawTextLoc]) - { - switch(rawText[rawTextLoc]) - { - case '\\': - outputData[outputDataLoc++] = rawText[rawTextLoc++]; - if(rawText[rawTextLoc]) - outputData[outputDataLoc++] = rawText[rawTextLoc++]; - break; - case '"': - if(pstack.size() && pstack.top() == '"') - { - pstack.pop(); - outputData[outputDataLoc++] = rawText[rawTextLoc++]; - outputData[outputDataLoc++] = '\b'; - outputData[outputDataLoc++] = 'w'; - } - else - { - pstack.push('"'); - outputData[outputDataLoc++] = '\b'; - outputData[outputDataLoc++] = 'o'; - outputData[outputDataLoc++] = rawText[rawTextLoc++]; - } - break; - default: - outputData[outputDataLoc++] = rawText[rawTextLoc++]; - break; - } - } - return outputData; + return commandInterface->FormatCommand(command); } void ConsoleController::NextCommand() diff --git a/src/console/ConsoleController.h b/src/console/ConsoleController.h index 9316f71..d5fc07a 100644 --- a/src/console/ConsoleController.h +++ b/src/console/ConsoleController.h @@ -13,6 +13,7 @@ #include "ConsoleView.h" #include "ConsoleModel.h" #include "ConsoleCommand.h" +#include "cat/CommandInterface.h" class ConsoleModel; class ConsoleView; @@ -20,14 +21,16 @@ class ConsoleController { ControllerCallback * callback; ConsoleView * consoleView; ConsoleModel * consoleModel; + CommandInterface * commandInterface; public: bool HasDone; - ConsoleController(ControllerCallback * callback); + ConsoleController(ControllerCallback * callback, CommandInterface * commandInterface); std::string FormatCommand(std::string command); void EvaluateCommand(std::string command); void NextCommand(); void PreviousCommand(); void Exit(); + void CloseConsole(); ConsoleView * GetView(); virtual ~ConsoleController(); }; diff --git a/src/console/ConsoleView.cpp b/src/console/ConsoleView.cpp index 117d8cb..f36a33b 100644 --- a/src/console/ConsoleView.cpp +++ b/src/console/ConsoleView.cpp @@ -34,6 +34,9 @@ void ConsoleView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, b { switch(key) { + case '`': + c->CloseConsole(); + break; case KEY_RETURN: case KEY_ENTER: c->EvaluateCommand(commandField->GetText()); @@ -63,7 +66,11 @@ void ConsoleView::NotifyPreviousCommandsChanged(ConsoleModel * sender) { if(currentY <= 0) break; - ui::Label * tempLabel = new ui::Label(ui::Point(0, currentY), ui::Point(Size.X, 16), commands[i].Command); + ui::Label * tempLabel = new ui::Label(ui::Point(Size.X/2, currentY), ui::Point(Size.X/2, 16), commands[i].ReturnValue); + tempLabel->SetAlignment(AlignLeft, AlignMiddle); + commandList.push_back(tempLabel); + AddComponent(tempLabel); + tempLabel = new ui::Label(ui::Point(0, currentY), ui::Point(Size.X/2, 16), commands[i].Command); tempLabel->SetAlignment(AlignLeft, AlignMiddle); commandList.push_back(tempLabel); AddComponent(tempLabel); |
