Changeset 6015
- Timestamp:
- Nov 2, 2009, 5:54:13 PM (15 years ago)
- Location:
- code/branches/console/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/libraries/core/Core.cc
r6004 r6015 218 218 this->languageInstance_.reset(new Language()); 219 219 220 // create persistent io console 221 this->ioConsole_.reset(new IOConsole()); 222 220 223 // creates the class hierarchy for all classes with factories 221 224 Identifier::createClassHierarchy(); … … 231 234 this->tclBind_.reset(new TclBind(PathConfig::getDataPathString())); 232 235 this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter())); 233 234 // create persistent io console235 this->ioConsole_.reset(new IOConsole());236 236 237 237 // Create singletons that always exist (in other libraries) -
code/branches/console/src/libraries/core/Core.h
r6004 r6015 91 91 scoped_ptr<ConfigFileManager> configFileManager_; 92 92 scoped_ptr<Language> languageInstance_; 93 scoped_ptr<IOConsole> ioConsole_; 93 94 scoped_ptr<CoreConfiguration> configuration_; 94 95 scoped_ptr<TclBind> tclBind_; 95 96 scoped_ptr<TclThreadManager> tclThreadManager_; 96 scoped_ptr<IOConsole> ioConsole_;97 97 // graphical 98 98 scoped_ptr<GraphicsManager> graphicsManager_; //!< Interface to OGRE -
code/branches/console/src/libraries/core/IOConsole.cc
r6014 r6015 30 30 #include "IOConsole.h" 31 31 32 #include <cstring>33 32 #include <iomanip> 34 33 #include <iostream> 35 36 #include "util/Clock.h"37 #include "util/Debug.h"38 #include "util/Sleep.h"39 #include "core/CommandExecutor.h"40 34 #include "core/Game.h" 41 #include "core/GameMode.h"42 #include "core/Shell.h"43 35 #include "core/input/InputBuffer.h" 44 36 37 // ########################## 38 // ### Mutual methods ### 39 // ########################## 40 namespace orxonox 41 { 42 IOConsole* IOConsole::singletonPtr_s = NULL; 43 44 int IOConsole::extractLogLevel(std::string* text) 45 { 46 // Handle line colouring by inspecting the first letter 47 char level = 0; 48 if (!text->empty()) 49 { 50 level = (*text)[0]; 51 if (level == -1 || level >= 1 && level <= 6) 52 { 53 *text = text->substr(1); 54 if (level != -1) 55 return level; 56 } 57 } 58 return 0; 59 } 60 61 inline bool IOConsole::willPrintStatusLines() 62 { 63 return !this->statusLineWidths_.empty() 64 && this->terminalWidth_ >= this->statusLineMaxWidth_ 65 && this->terminalHeight_ >= (this->minOutputLines_ + this->statusLineWidths_.size()); 66 } 67 68 // ############################### 69 // ### ShellListener methods ### 70 // ############################### 71 72 //! Called if all output-lines have to be reprinted 73 void IOConsole::linesChanged() 74 { 75 // Method only gets called upon start to draw all the lines 76 // or when scrolling. But scrolling is disable and the output 77 // is already in std::cout when we start the IOConsole 78 } 79 80 //! Called if the text in the input-line has changed 81 void IOConsole::inputChanged() 82 { 83 this->printInputLine(); 84 std::cout.flush(); 85 } 86 87 //! Called if the position of the cursor in the input-line has changed 88 void IOConsole::cursorChanged() 89 { 90 this->printInputLine(); 91 std::cout.flush(); 92 } 93 94 //! Called if a command is about to be executed 95 void IOConsole::executed() 96 { 97 this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput()); 98 } 99 100 //! Called if the console gets closed 101 void IOConsole::exit() 102 { 103 // Exit is not an option, just do nothing (Shell doesn't really exit too) 104 } 105 } 106 45 107 #ifdef ORXONOX_PLATFORM_UNIX 108 // ############################### 109 // ### Unix Implementation ### 110 // ############################### 111 46 112 #include <termios.h> 47 113 #include <sys/ioctl.h> 48 114 #include <sys/stat.h> 49 #endif50 115 51 116 namespace orxonox 52 117 { 53 IOConsole* IOConsole::singletonPtr_s = NULL;54 55 #ifdef ORXONOX_PLATFORM_UNIX56 57 118 namespace EscapeMode 58 119 { … … 82 143 this->lastTerminalWidth_ = this->terminalWidth_; 83 144 this->lastTerminalHeight_ = this->terminalHeight_; 145 146 // Disable standard std::cout logging 147 OutputHandler::getInstance().disableCout(); 84 148 } 85 149 86 150 IOConsole::~IOConsole() 87 151 { 88 // Goto last line and erase it152 // Goto last line and create a new one 89 153 if (this->bStatusPrinted_) 90 154 std::cout << "\033[" << this->statusLineWidths_.size() << 'E'; 91 std::cout << "\033[1G\033[K";92 std::cout.flush(); 155 std::cout << std::endl; 156 93 157 resetTerminalMode(); 94 158 delete this->originalTerminalSettings_; 95 159 this->shell_->destroy(); 96 } 97 98 void IOConsole::setTerminalMode() 99 { 100 termios new_settings; 101 102 tcgetattr(0, this->originalTerminalSettings_); 103 new_settings = *this->originalTerminalSettings_; 104 new_settings.c_lflag &= ~(ICANON | ECHO); 105 // new_settings.c_lflag |= ( ISIG | IEXTEN ); 106 new_settings.c_cc[VTIME] = 0; 107 new_settings.c_cc[VMIN] = 0; 108 tcsetattr(0, TCSANOW, &new_settings); 109 COUT(0) << endl; 110 // atexit(&IOConsole::resetTerminalMode); 111 } 112 113 void IOConsole::resetTerminalMode() 114 { 115 tcsetattr(0, TCSANOW, IOConsole::originalTerminalSettings_); 160 161 // Enable standard std::cout logging again 162 OutputHandler::getInstance().enableCout(); 116 163 } 117 164 … … 121 168 std::string escapeSequence; 122 169 EscapeMode::Value escapeMode = EscapeMode::None; 123 while (read(STDIN_FILENO, &c, 1) == 1) 124 { 170 while (std::cin.good()) 171 { 172 c = std::cin.get(); 173 if (std::cin.bad()) 174 break; 175 125 176 if (escapeMode == EscapeMode::First && (c == '[' || c=='O') ) 126 177 escapeMode = EscapeMode::Second; … … 191 242 } 192 243 } 244 // Reset error flags in std::cin 245 std::cin.clear(); 193 246 194 247 // If there is still an escape key pending (escape key ONLY), then … … 205 258 if (this->bStatusPrinted_ && heightDiff < 0) 206 259 { 207 // Terminal width has shr inked. The cursor will still be on the input line,260 // Terminal width has shrunk. The cursor will still be on the input line, 208 261 // but that line might very well be the last 209 262 int newLines = std::min((int)this->statusLineWidths_.size(), -heightDiff); … … 230 283 void IOConsole::printLogText(const std::string& text) 231 284 { 232 std::string output; 233 234 // Handle line colouring by inspecting the first letter 235 char level = 0; 236 if (!text.empty()) 237 level = text[0]; 238 if (level >= -1 && level <= 6) 239 output = text.substr(1); 240 else 241 output = text; 285 std::string output = text; 286 int level = this->extractLogLevel(&output); 242 287 243 288 // Colour line … … 297 342 } 298 343 299 inline bool IOConsole::willPrintStatusLines() 300 { 301 return !this->statusLineWidths_.empty() 302 && this->terminalWidth_ >= this->statusLineMaxWidth_ 303 && this->terminalHeight_ >= (this->minOutputLines_ + this->statusLineWidths_.size()); 344 void IOConsole::setTerminalMode() 345 { 346 termios new_settings; 347 348 tcgetattr(0, this->originalTerminalSettings_); 349 new_settings = *this->originalTerminalSettings_; 350 new_settings.c_lflag &= ~(ICANON | ECHO); 351 //new_settings.c_lflag |= (ISIG | IEXTEN); 352 new_settings.c_cc[VTIME] = 0; 353 new_settings.c_cc[VMIN] = 0; 354 tcsetattr(0, TCSANOW, &new_settings); 355 } 356 357 void IOConsole::resetTerminalMode() 358 { 359 tcsetattr(0, TCSANOW, IOConsole::originalTerminalSettings_); 304 360 } 305 361 … … 333 389 } 334 390 335 #elif defined(ORXONOX_PLATFORM_WINDOWS)336 337 IOConsole::IOConsole()338 : shell_(new Shell("IOConsole", false))339 , buffer_(shell_->getInputBuffer())340 {341 this->setTerminalMode();342 }343 344 IOConsole::~IOConsole()345 {346 }347 348 void IOConsole::setTerminalMode()349 {350 }351 352 void IOConsole::resetTerminalMode()353 {354 }355 356 void IOConsole::update(const Clock& time)357 {358 }359 360 void IOConsole::printLogText(const std::string& text)361 {362 }363 364 void IOConsole::printInputLine()365 {366 }367 368 void IOConsole::printStatusLines()369 {370 }371 372 #endif /* ORXONOX_PLATFORM_UNIX */373 374 391 // ############################### 375 392 // ### ShellListener methods ### 376 393 // ############################### 377 394 378 /** 379 @brief 380 Called if all output-lines have to be redrawn. 381 */ 382 void IOConsole::linesChanged() 383 { 384 // Method only gets called upon start to draw all the lines 385 // But we are using std::cout anyway, so do nothing here 386 } 387 388 /** 389 @brief 390 Called if only the last output-line has changed. 391 */ 395 //! Called if only the last output-line has changed 392 396 void IOConsole::onlyLastLineChanged() 393 397 { … … 403 407 } 404 408 405 /** 406 @brief 407 Called if a new output-line was added. 408 */ 409 //! Called if a new output-line was added 409 410 void IOConsole::lineAdded() 410 411 { … … 429 430 std::cout.flush(); 430 431 } 431 432 /**433 @brief434 Called if the text in the input-line has changed.435 */436 void IOConsole::inputChanged()437 {438 this->printInputLine();439 std::cout.flush();440 }441 442 /**443 @brief444 Called if the position of the cursor in the input-line has changed.445 */446 void IOConsole::cursorChanged()447 {448 this->printInputLine();449 std::cout.flush();450 }451 452 /**453 @brief454 Called if a command is about to be executed455 */456 void IOConsole::executed()457 {458 this->shell_->addOutputLine(this->promptString_ + this->shell_->getInput());459 }460 461 462 /**463 @brief464 Called if the console gets closed.465 */466 void IOConsole::exit()467 {468 // Exit is not an option, IOConsole always exists469 }470 471 432 } 433 434 #elif defined(ORXONOX_PLATFORM_WINDOWS) 435 // ################################## 436 // ### Windows Implementation ### 437 // ################################## 438 439 namespace orxonox 440 { 441 IOConsole::IOConsole() 442 : shell_(new Shell("IOConsole", false, true)) 443 , buffer_(shell_->getInputBuffer()) 444 , bStatusPrinted_(false) 445 , promptString_("orxonox # ") 446 { 447 /* 448 this->setTerminalMode(); 449 this->shell_->registerListener(this); 450 451 // Manually set the widths of the individual status lines 452 this->statusLineWidths_.push_back(29); 453 this->statusLineMaxWidth_ = 29; 454 455 this->getTerminalSize(); 456 this->lastTerminalWidth_ = this->terminalWidth_; 457 this->lastTerminalHeight_ = this->terminalHeight_; 458 459 // Disable standard std::cout logging 460 OutputHandler::getInstance().disableCout(); 461 */ 462 } 463 464 IOConsole::~IOConsole() 465 { 466 /* 467 resetTerminalMode(); 468 this->shell_->destroy(); 469 470 // Enable standard std::cout logging again 471 OutputHandler::getInstance().enableCout(); 472 */ 473 } 474 475 void IOConsole::update(const Clock& time) 476 { 477 /* 478 unsigned char c = 0; 479 while (std::cin.good()) 480 { 481 c = std::cin.get(); 482 if (std::cin.bad()) 483 break; 484 } 485 // Reset error flags in std::cin 486 std::cin.clear(); 487 488 // Determine terminal width and height 489 this->lastTerminalWidth_ = this->terminalWidth_; 490 this->lastTerminalHeight_ = this->terminalHeight_; 491 this->getTerminalSize(); 492 */ 493 } 494 495 void IOConsole::printLogText(const std::string& text) 496 { 497 } 498 499 void IOConsole::printInputLine() 500 { 501 } 502 503 void IOConsole::printStatusLines() 504 { 505 /* 506 if (this->willPrintStatusLines()) 507 { 508 this->bStatusPrinted_ = true; 509 } 510 else 511 this->bStatusPrinted_ = false; 512 */ 513 } 514 515 void IOConsole::setTerminalMode() 516 { 517 } 518 519 void IOConsole::resetTerminalMode() 520 { 521 } 522 523 void IOConsole::getTerminalSize() 524 { 525 } 526 527 // ############################### 528 // ### ShellListener methods ### 529 // ############################### 530 531 //! Called if only the last output-line has changed 532 void IOConsole::onlyLastLineChanged() 533 { 534 } 535 536 //! Called if a new output-line was added 537 void IOConsole::lineAdded() 538 { 539 } 540 } 541 542 #endif /* ORXONOX_PLATFORM_UNIX */ -
code/branches/console/src/libraries/core/IOConsole.h
r6014 r6015 33 33 #include "CorePrereqs.h" 34 34 35 #include < queue>36 #include < boost/scoped_ptr.hpp>35 #include <string> 36 #include <vector> 37 37 #include "util/Singleton.h" 38 38 #include "core/Shell.h" 39 39 40 #ifdef ORXONOX_PLATFORM_UNIX 40 41 struct termios; 42 #endif 41 43 42 44 namespace orxonox … … 53 55 54 56 private: 55 56 57 void setTerminalMode(); 57 58 void resetTerminalMode(); 58 59 void getTerminalSize(); 59 60 bool willPrintStatusLines(); 61 int extractLogLevel(std::string* text); 60 62 61 63 void printLogText(const std::string& line); … … 71 73 void executed(); 72 74 void exit(); 73 74 75 Shell* shell_; 75 76 InputBuffer* buffer_; 76 termios* originalTerminalSettings_;77 77 unsigned int terminalWidth_; 78 78 unsigned int terminalHeight_; … … 86 86 static const unsigned minOutputLines_ = 3; 87 87 88 #ifdef ORXONOX_PLATFORM_UNIX 89 termios* originalTerminalSettings_; 90 #endif 91 88 92 static IOConsole* singletonPtr_s; 89 93 }; -
code/branches/console/src/libraries/util/OutputHandler.cc
r6007 r6015 118 118 std::ofstream logFile_; //! File handle for the log file 119 119 std::string logFilename_; //! Filename of the log file 120 }; 121 122 123 ///////////////////////// 124 ///// ConsoleWriter ///// 125 ///////////////////////// 126 /** 127 @brief 128 Writes the output to std::cout. 129 @note 130 This listener will usually be disable once an actual shell with console is instantiated. 131 */ 132 class ConsoleWriter : public OutputListener 133 { 134 public: 135 //! Only assigns the output stream with std::cout 136 ConsoleWriter() 137 : OutputListener("consoleLog") 138 { 139 this->outputStream_ = &std::cout; 140 } 120 141 }; 121 142 … … 176 197 : outputLevel_(OutputLevel::Verbose) 177 198 { 199 #ifdef ORXONOX_RELEASE 200 const OutputLevel::Value defaultLevelConsole = OutputLevel::Error; 201 const OutputLevel::Value defaultLevelLogFile = OutputLevel::Info; 202 #else 203 const OutputLevel::Value defaultLevelConsole = OutputLevel::Info; 204 const OutputLevel::Value defaultLevelLogFile = OutputLevel::Debug; 205 #endif 206 178 207 this->logFile_ = new LogFileWriter(); 179 208 // Use default level until we get the configValue from the Core 180 this->logFile_->softDebugLevel_ = OutputLevel::Debug;209 this->logFile_->softDebugLevel_ = defaultLevelLogFile; 181 210 this->registerOutputListener(this->logFile_); 211 212 this->consoleWriter_ = new ConsoleWriter(); 213 this->consoleWriter_->softDebugLevel_ = defaultLevelConsole; 214 this->registerOutputListener(this->consoleWriter_); 182 215 183 216 this->output_ = new MemoryLogWriter(); … … 225 258 } 226 259 260 void OutputHandler::disableCout() 261 { 262 this->unregisterOutputListener(this->consoleWriter_); 263 } 264 265 void OutputHandler::enableCout() 266 { 267 this->registerOutputListener(this->consoleWriter_); 268 } 269 227 270 OutputHandler::OutputVectorIterator OutputHandler::getOutputVectorBegin() const 228 271 { -
code/branches/console/src/libraries/util/OutputHandler.h
r6004 r6015 74 74 // Forward declarations for classes in the source file 75 75 class LogFileWriter; 76 class ConsoleWriter; 76 77 class MemoryLogWriter; 77 78 … … 129 130 //! Set the log path once the program has been properly initialised 130 131 void setLogPath(const std::string& path); 132 //! Disables the std::cout stream for output 133 void disableCout(); 134 //! Enables the std::cout stream for output (startup behaviour) 135 void enableCout(); 131 136 132 137 //! Sets the level of the incoming output and returns the OutputHandler … … 210 215 OutputHandler(const OutputHandler& rhs); //! Unused and undefined 211 216 212 std::list<OutputListener*> listeners_; //!< Array with all registered output listeners 213 int outputLevel_; //!< The level of the incoming output 214 LogFileWriter* logFile_; //!< Listener that writes to the log file 215 MemoryLogWriter* output_; //!< Listener that Stores ALL output below the current soft debug level 216 static int softDebugLevel_s; //!< Maximum of all soft debug levels. @note This is only static for faster access 217 std::list<OutputListener*> listeners_; //!< Array with all registered output listeners 218 int outputLevel_; //!< The level of the incoming output 219 LogFileWriter* logFile_; //!< Listener that writes to the log file 220 ConsoleWriter* consoleWriter_; //!< Listener for std::cout (just program beginning) 221 MemoryLogWriter* output_; //!< Listener that Stores ALL output below the current soft debug level 222 static int softDebugLevel_s; //!< Maximum of all soft debug levels. @note This is only static for faster access 217 223 }; 218 224 -
code/branches/console/src/orxonox/overlays/InGameConsole.cc
r6010 r6015 336 336 337 337 /** 338 @brief Called if a command is about to be executed 339 */ 340 void InGameConsole::executed() 341 { 342 this->shell_->addOutputLine(this->shell_->getInput()); 343 } 344 345 /** 338 346 @brief Called if the console gets closed. 339 347 */ -
code/branches/console/src/orxonox/overlays/InGameConsole.h
r6004 r6015 68 68 void inputChanged(); 69 69 void cursorChanged(); 70 void executed(); 70 71 void exit(); 71 72
Note: See TracChangeset
for help on using the changeset viewer.