Changeset 6010
- Timestamp:
- Oct 31, 2009, 11:13:52 PM (15 years ago)
- Location:
- code/branches/console/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/libraries/core/IOConsole.cc
r6007 r6010 50 50 { 51 51 IOConsole* IOConsole::singletonPtr_s = NULL; 52 const std::string promptString_g = "orxonox>";53 52 54 53 #ifdef ORXONOX_PLATFORM_UNIX … … 65 64 66 65 IOConsole::IOConsole() 67 : shell_(new Shell("IOConsole", false ))66 : shell_(new Shell("IOConsole", false, true)) 68 67 , buffer_(shell_->getInputBuffer()) 69 68 , originalTerminalSettings_(new termios()) 70 69 , bStatusPrinted_(false) 70 , promptString_("orxonox> ") 71 71 { 72 72 this->setTerminalMode(); … … 143 143 this->buffer_->buttonPressed(KeyEvent(KeyCode::End, 0, 0)); 144 144 else if (escapeSequence == "5~") 145 this->buffer_->buttonPressed(KeyEvent(KeyCode:: AltPageUp, 0, 0));145 this->buffer_->buttonPressed(KeyEvent(KeyCode::PageUp, 0, 0)); 146 146 else if (escapeSequence == "6~") 147 this->buffer_->buttonPressed(KeyEvent(KeyCode:: AltPageDown, 0, 0));147 this->buffer_->buttonPressed(KeyEvent(KeyCode::PageDown, 0, 0)); 148 148 else 149 149 // Waiting for sequence to complete … … 192 192 this->printStatusLines(); 193 193 this->printInputLine(); 194 std::cout.flush(); 194 195 } 195 196 … … 227 228 // Reset colour to white 228 229 // std::cout << "\033[37m"; 229 std::cout.flush();230 230 } 231 231 … … 244 244 if (this->buffer_->getCursorPosition() > 0) 245 245 std::cout << "\033[" << this->buffer_->getCursorPosition() << "C"; 246 std::cout.flush();247 246 } 248 247 … … 259 258 } 260 259 std::cout << "Status" << std::endl; 261 std::cout.flush();262 260 this->bStatusPrinted_ = true; 263 261 } … … 332 330 } 333 331 332 void IOConsole::printStatusLines() 333 { 334 } 335 334 336 #endif /* ORXONOX_PLATFORM_UNIX */ 335 337 … … 378 380 this->printStatusLines(); 379 381 this->printInputLine(); 382 std::cout.flush(); 380 383 } 381 384 … … 387 390 { 388 391 this->printInputLine(); 392 std::cout.flush(); 389 393 } 390 394 … … 396 400 { 397 401 this->printInputLine(); 402 std::cout.flush(); 398 403 } 399 404 … … 404 409 void IOConsole::executed() 405 410 { 406 // Move cursor the beginning of the line 407 std::cout << "\033[1G"; 408 // Print command so the user knows what he has typed 409 std::cout << promptString_g << this->shell_->getInput() << std::endl; 410 this->printInputLine(); 411 this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput()); 411 412 } 412 413 -
code/branches/console/src/libraries/core/IOConsole.h
r6007 r6010 77 77 std::vector<unsigned> statusLineWidths_; 78 78 unsigned int statusLineMaxWidth_; 79 const std::string promptString_; 79 80 static const unsigned minOutputLines_ = 3; 80 81 -
code/branches/console/src/libraries/core/Shell.cc
r6004 r6010 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 44 44 SetConsoleCommandShortcut(OutputHandler, debug); 45 45 46 Shell::Shell(const std::string& consoleName, bool bScrollable )47 : inputBuffer_(new InputBuffer())48 , OutputListener(consoleName)46 Shell::Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel) 47 : OutputListener(consoleName) 48 , inputBuffer_(new InputBuffer()) 49 49 , consoleName_(consoleName) 50 , bPrependOutputLevel_(bPrependOutputLevel) 50 51 , bScrollable_(bScrollable) 51 52 { … … 56 57 this->historyPosition_ = 0; 57 58 this->historyOffset_ = 0; 58 this->finishedLastLine_ = true; 59 this->bAddOutputLevel_ = false; 60 61 this->clearLines(); 59 this->bFinishedLastLine_ = true; 60 61 this->clearOutput(); 62 62 this->configureInputBuffer(); 63 63 … … 131 131 { 132 132 this->inputBuffer_->registerListener(this, &Shell::inputChanged, true); 133 this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false); 134 this->inputBuffer_->registerListener(this, &Shell::execute, '\n', false); 135 this->inputBuffer_->registerListener(this, &Shell::hintandcomplete, '\t', true); 136 this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true); 137 this->inputBuffer_->registerListener(this, &Shell::backspace, '\177', true); 138 this->inputBuffer_->registerListener(this, &Shell::deletechar, KeyCode::Delete); 139 this->inputBuffer_->registerListener(this, &Shell::exit, '\033', true); // escape 140 this->inputBuffer_->registerListener(this, &Shell::cursor_right, KeyCode::Right); 141 this->inputBuffer_->registerListener(this, &Shell::cursor_left, KeyCode::Left); 142 this->inputBuffer_->registerListener(this, &Shell::cursor_end, KeyCode::End); 143 this->inputBuffer_->registerListener(this, &Shell::cursor_home, KeyCode::Home); 144 this->inputBuffer_->registerListener(this, &Shell::history_up, KeyCode::Up); 145 this->inputBuffer_->registerListener(this, &Shell::history_down, KeyCode::Down); 146 this->inputBuffer_->registerListener(this, &Shell::scroll_up, KeyCode::PageUp); 147 this->inputBuffer_->registerListener(this, &Shell::scroll_down, KeyCode::PageDown); 148 this->inputBuffer_->registerListener(this, &Shell::history_search_up, KeyCode::AltPageUp); 149 this->inputBuffer_->registerListener(this, &Shell::history_search_down, KeyCode::AltPageDown); 133 this->inputBuffer_->registerListener(this, &Shell::execute, '\r', false); 134 this->inputBuffer_->registerListener(this, &Shell::execute, '\n', false); 135 this->inputBuffer_->registerListener(this, &Shell::hintAndComplete, '\t', true); 136 this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true); 137 this->inputBuffer_->registerListener(this, &Shell::backspace, '\177', true); 138 this->inputBuffer_->registerListener(this, &Shell::exit, '\033', true); // escape 139 this->inputBuffer_->registerListener(this, &Shell::deleteChar, KeyCode::Delete); 140 this->inputBuffer_->registerListener(this, &Shell::cursorRight, KeyCode::Right); 141 this->inputBuffer_->registerListener(this, &Shell::cursorLeft, KeyCode::Left); 142 this->inputBuffer_->registerListener(this, &Shell::cursorEnd, KeyCode::End); 143 this->inputBuffer_->registerListener(this, &Shell::cursorHome, KeyCode::Home); 144 this->inputBuffer_->registerListener(this, &Shell::historyUp, KeyCode::Up); 145 this->inputBuffer_->registerListener(this, &Shell::historyDown, KeyCode::Down); 146 if (this->bScrollable_) 147 { 148 this->inputBuffer_->registerListener(this, &Shell::scrollUp, KeyCode::PageUp); 149 this->inputBuffer_->registerListener(this, &Shell::scrollDown, KeyCode::PageDown); 150 } 151 else 152 { 153 this->inputBuffer_->registerListener(this, &Shell::historySearchUp, KeyCode::PageUp); 154 this->inputBuffer_->registerListener(this, &Shell::historySearchDown, KeyCode::PageDown); 155 } 150 156 } 151 157 … … 156 162 157 163 for (unsigned int i = instance.historyOffset_; i < instance.commandHistory_.size(); ++i) 158 instance.add Line(instance.commandHistory_[i], -1);164 instance.addOutputLine(instance.commandHistory_[i], -1); 159 165 for (unsigned int i = 0; i < instance.historyOffset_; ++i) 160 instance.add Line(instance.commandHistory_[i], -1);166 instance.addOutputLine(instance.commandHistory_[i], -1); 161 167 } 162 168 */ … … 184 190 } 185 191 186 void Shell::setInput(const std::string& input) 187 { 188 this->inputBuffer_->set(input); 189 this->inputChanged(); 190 } 191 192 void Shell::addLine(const std::string& line, int level) 192 void Shell::addOutputLine(const std::string& line, int level) 193 193 { 194 194 if (level <= this->softDebugLevel_) … … 197 197 } 198 198 199 void Shell::clear Lines()199 void Shell::clearOutput() 200 200 { 201 201 this->outputLines_.clear(); … … 203 203 204 204 this->scrollPosition_ = 0; 205 this-> finishedLastLine_ = true;205 this->bFinishedLastLine_ = true; 206 206 207 207 this->updateListeners<&ShellListener::linesChanged>(); … … 256 256 break; 257 257 258 if (this-> finishedLastLine_)258 if (this->bFinishedLastLine_) 259 259 { 260 if (this->b AddOutputLevel_)260 if (this->bPrependOutputLevel_) 261 261 output.insert(0, 1, static_cast<char>(level)); 262 262 … … 268 268 this->scrollIterator_ = this->outputLines_.begin(); 269 269 270 this-> finishedLastLine_ = newline;270 this->bFinishedLastLine_ = newline; 271 271 272 272 if (!this->scrollPosition_) … … 278 278 { 279 279 (*this->outputLines_.begin()) += output; 280 this-> finishedLastLine_ = newline;280 this->bFinishedLastLine_ = newline; 281 281 this->updateListeners<&ShellListener::onlyLastLineChanged>(); 282 282 } … … 285 285 } 286 286 287 void Shell::inputChanged() 288 { 289 this->updateListeners<&ShellListener::inputChanged>(); 290 this->updateListeners<&ShellListener::cursorChanged>(); 291 } 292 293 void Shell::execute() 294 { 295 this->addToHistory(this->inputBuffer_->get()); 296 this->updateListeners<&ShellListener::executed>(); 297 298 if (!CommandExecutor::execute(this->inputBuffer_->get())) 299 this->addLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1); 300 301 this->clear(); 302 } 303 304 void Shell::hintandcomplete() 305 { 306 this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get())); 307 this->addLine(CommandExecutor::hint(this->inputBuffer_->get()), -1); 308 309 this->inputChanged(); 310 } 311 312 void Shell::backspace() 313 { 314 this->inputBuffer_->removeBehindCursor(); 315 this->updateListeners<&ShellListener::inputChanged>(); 316 this->updateListeners<&ShellListener::cursorChanged>(); 317 } 318 319 void Shell::deletechar() 320 { 321 this->inputBuffer_->removeAtCursor(); 322 this->updateListeners<&ShellListener::inputChanged>(); 323 } 324 325 void Shell::clear() 287 void Shell::clearInput() 326 288 { 327 289 this->inputBuffer_->clear(); … … 331 293 } 332 294 333 void Shell::cursor_right() 295 void Shell::setPromptPrefix(const std::string& str) 296 { 297 } 298 299 300 // ########################################## 301 // ### InputBuffer callback functions ### 302 // ########################################## 303 304 void Shell::inputChanged() 305 { 306 this->updateListeners<&ShellListener::inputChanged>(); 307 this->updateListeners<&ShellListener::cursorChanged>(); 308 } 309 310 void Shell::execute() 311 { 312 this->addToHistory(this->inputBuffer_->get()); 313 this->updateListeners<&ShellListener::executed>(); 314 315 if (!CommandExecutor::execute(this->inputBuffer_->get())) 316 this->addOutputLine("Error: Can't execute \"" + this->inputBuffer_->get() + "\".", 1); 317 318 this->clearInput(); 319 } 320 321 void Shell::hintAndComplete() 322 { 323 this->inputBuffer_->set(CommandExecutor::complete(this->inputBuffer_->get())); 324 this->addOutputLine(CommandExecutor::hint(this->inputBuffer_->get()), -1); 325 326 this->inputChanged(); 327 } 328 329 void Shell::backspace() 330 { 331 this->inputBuffer_->removeBehindCursor(); 332 this->updateListeners<&ShellListener::inputChanged>(); 333 this->updateListeners<&ShellListener::cursorChanged>(); 334 } 335 336 void Shell::exit() 337 { 338 if (this->inputBuffer_->getSize() > 0) 339 { 340 this->clearInput(); 341 return; 342 } 343 344 this->clearInput(); 345 this->scrollPosition_ = 0; 346 this->scrollIterator_ = this->outputLines_.begin(); 347 348 this->updateListeners<&ShellListener::exit>(); 349 } 350 351 void Shell::deleteChar() 352 { 353 this->inputBuffer_->removeAtCursor(); 354 this->updateListeners<&ShellListener::inputChanged>(); 355 } 356 357 void Shell::cursorRight() 334 358 { 335 359 this->inputBuffer_->increaseCursor(); … … 337 361 } 338 362 339 void Shell::cursor _left()363 void Shell::cursorLeft() 340 364 { 341 365 this->inputBuffer_->decreaseCursor(); … … 343 367 } 344 368 345 void Shell::cursor _end()369 void Shell::cursorEnd() 346 370 { 347 371 this->inputBuffer_->setCursorToEnd(); … … 349 373 } 350 374 351 void Shell::cursor _home()375 void Shell::cursorHome() 352 376 { 353 377 this->inputBuffer_->setCursorToBegin(); … … 355 379 } 356 380 357 void Shell::history _up()381 void Shell::historyUp() 358 382 { 359 383 if (this->historyPosition_ < this->commandHistory_.size()) … … 364 388 } 365 389 366 void Shell::history _down()390 void Shell::historyDown() 367 391 { 368 392 if (this->historyPosition_ > 0) … … 373 397 } 374 398 375 void Shell::history _search_up()399 void Shell::historySearchUp() 376 400 { 377 401 if (this->historyPosition_ == this->historyOffset_) 378 402 return; 379 403 unsigned int cursorPosition = this->getCursorPosition(); 380 std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline until lthe cursor position404 std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning of the inputline until the cursor position 381 405 for (unsigned int newPos = this->historyPosition_ + 1; newPos <= this->historyOffset_; newPos++) 382 406 { … … 391 415 } 392 416 393 void Shell::history _search_down()417 void Shell::historySearchDown() 394 418 { 395 419 if (this->historyPosition_ == 0) 396 420 return; 397 421 unsigned int cursorPosition = this->getCursorPosition(); 398 std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginn $422 std::string input_str(this->getInput().substr(0, cursorPosition)); // only search for the expression from the beginning 399 423 for (unsigned int newPos = this->historyPosition_ - 1; newPos > 0; newPos--) 400 424 { … … 409 433 } 410 434 411 void Shell::scroll _up()435 void Shell::scrollUp() 412 436 { 413 437 if (this->scrollIterator_ != this->outputLines_.end()) … … 420 444 } 421 445 422 void Shell::scroll _down()446 void Shell::scrollDown() 423 447 { 424 448 if (this->scrollIterator_ != this->outputLines_.begin()) … … 430 454 } 431 455 } 432 433 void Shell::exit()434 {435 if (this->inputBuffer_->getSize() > 0)436 {437 this->clear();438 return;439 }440 441 this->clear();442 this->scrollPosition_ = 0;443 this->scrollIterator_ = this->outputLines_.begin();444 445 this->updateListeners<&ShellListener::exit>();446 }447 456 } -
code/branches/console/src/libraries/core/Shell.h
r6004 r6010 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 61 61 }; 62 62 63 63 64 class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener 64 65 { 65 66 public: 66 Shell(const std::string& consoleName, bool bScrollable );67 virtual~Shell();67 Shell(const std::string& consoleName, bool bScrollable, bool bPrependOutputLevel = false); 68 ~Shell(); 68 69 69 70 void setConfigValues(); … … 81 82 { return this->inputBuffer_->getCursorPosition(); } 82 83 83 void setInput(const std::string& input);84 85 inline void clearInput()86 { this->setInput(""); }87 84 inline std::string getInput() const 88 85 { return this->inputBuffer_->get(); } … … 91 88 std::list<std::string>::const_iterator getEndIterator() const; 92 89 93 void add Line(const std::string& line, int level = 0);94 void clear Lines();90 void addOutputLine(const std::string& line, int level = 0); 91 void clearOutput(); 95 92 96 93 inline unsigned int getNumLines() const … … 99 96 { return this->scrollPosition_; } 100 97 101 inline void addOutputLevel(bool bAddOutputLevel)102 { this->bAddOutputLevel_ = bAddOutputLevel; }98 inline const std::string& getPromptPrefix() const { return this->promptPrefix_; } 99 void setPromptPrefix(const std::string& str); 103 100 104 101 private: 105 102 Shell(const Shell& other); 106 103 104 void addToHistory(const std::string& command); 105 std::string getFromHistory() const; 106 void clearInput(); 107 // OutputListener 108 void outputChanged(int level); 109 107 110 void configureInputBuffer(); 108 111 109 void addToHistory(const std::string& command); 110 std::string getFromHistory() const; 111 112 virtual void outputChanged(int level); 113 112 // InputBuffer callbacks 114 113 void inputChanged(); 115 114 void execute(); 116 void hint andcomplete();115 void hintAndComplete(); 117 116 void backspace(); 118 void deletechar(); 119 void clear(); 120 void cursor_right(); 121 void cursor_left(); 122 void cursor_end(); 123 void cursor_home(); 124 void history_up(); 125 void history_down(); 126 void history_search_up(); 127 void history_search_down(); 128 void scroll_up(); 129 void scroll_down(); 117 void deleteChar(); 118 void cursorRight(); 119 void cursorLeft(); 120 void cursorEnd(); 121 void cursorHome(); 122 void historyUp(); 123 void historyDown(); 124 void historySearchUp(); 125 void historySearchDown(); 126 void scrollUp(); 127 void scrollDown(); 130 128 void exit(); 131 129 … … 138 136 139 137 std::list<ShellListener*> listeners_; 140 InputBuffer* inputBuffer_;141 std::stringstream outputBuffer_;142 bool finishedLastLine_;143 std::list<std::string> outputLines_;138 InputBuffer* inputBuffer_; 139 std::stringstream outputBuffer_; 140 bool bFinishedLastLine_; 141 std::list<std::string> outputLines_; 144 142 std::list<std::string>::const_iterator scrollIterator_; 145 unsigned int scrollPosition_; 146 unsigned int historyPosition_; 147 bool bAddOutputLevel_; 148 ConfigFileType commandHistoryConfigFileType_; 149 const std::string consoleName_; 150 const bool bScrollable_; 143 unsigned int scrollPosition_; 144 unsigned int historyPosition_; 145 ConfigFileType commandHistoryConfigFileType_; 146 147 std::string promptPrefix_; 148 const std::string consoleName_; 149 const bool bPrependOutputLevel_; 150 const bool bScrollable_; 151 151 152 152 // Config values 153 unsigned int maxHistoryLength_;154 unsigned int historyOffset_;155 std::vector<std::string> commandHistory_;156 int softDebugLevel_;153 unsigned int maxHistoryLength_; 154 unsigned int historyOffset_; 155 std::vector<std::string> commandHistory_; 156 int softDebugLevel_; 157 157 }; 158 158 } -
code/branches/console/src/libraries/core/input/InputPrereqs.h
r5986 r6010 179 179 Up = OIS::KC_UP, // UpArrow on arrow keypad 180 180 PageUp = OIS::KC_PGUP, // PgUp on arrow keypad 181 AltPageUp = OIS::KC_PGUP+1, // Alternative PgUp for the IOConsole182 181 Left = OIS::KC_LEFT, // LeftArrow on arrow keypad 183 182 Right = OIS::KC_RIGHT, // RightArrow on arrow keypad … … 185 184 Down = OIS::KC_DOWN, // DownArrow on arrow keypad 186 185 PageDown = OIS::KC_PGDOWN, // PgDn on arrow keypad 187 AltPageDown = OIS::KC_END-1, // Alternative PgUp for IOConsole188 186 Insert = OIS::KC_INSERT, // Insert on arrow keypad 189 187 Delete = OIS::KC_DELETE, // Delete on arrow keypad … … 288 286 "UP", 289 287 "PageUp", 290 "", // used for AltPageUp288 "", 291 289 "Left", 292 290 "", 293 291 "Right", 294 "", // used for AltPageDown292 "", 295 293 "End", "Down", "PageDown", "Insert", "Delete", 296 294 "","","","","","","", -
code/branches/console/src/orxonox/overlays/InGameConsole.cc
r6004 r6010 68 68 */ 69 69 InGameConsole::InGameConsole() 70 : shell_(new Shell("InGameConsole", true ))70 : shell_(new Shell("InGameConsole", true, true)) 71 71 , consoleOverlay_(0) 72 72 , consoleOverlayContainer_(0) … … 255 255 // we take -1.2 because the border makes the panel bigger 256 256 this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight); 257 258 this->shell_->addOutputLevel(true);259 257 260 258 COUT(4) << "Info: InGameConsole initialized" << std::endl;
Note: See TracChangeset
for help on using the changeset viewer.