Changeset 6004 for code/branches/console/src/libraries/core
- Timestamp:
- Oct 30, 2009, 12:39:51 PM (15 years ago)
- Location:
- code/branches/console/src/libraries/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/libraries/core/Core.cc
r5994 r6004 67 67 #include "LuaState.h" 68 68 #include "ScopedSingletonManager.h" 69 #include "Shell.h"70 69 #include "TclBind.h" 71 70 #include "TclThreadManager.h" … … 233 232 this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter())); 234 233 235 // create a shell236 this->shell_.reset(new Shell());237 234 // create persistent io console 238 235 this->ioConsole_.reset(new IOConsole()); -
code/branches/console/src/libraries/core/Core.h
r5994 r6004 94 94 scoped_ptr<TclBind> tclBind_; 95 95 scoped_ptr<TclThreadManager> tclThreadManager_; 96 scoped_ptr<Shell> shell_;97 96 scoped_ptr<IOConsole> ioConsole_; 98 97 // graphical -
code/branches/console/src/libraries/core/IOConsole.cc
r5998 r6004 52 52 const std::string promptString_g = "orxonox>"; 53 53 54 #if 1//def ORXONOX_PLATFORM_UNIX54 #ifdef ORXONOX_PLATFORM_UNIX 55 55 56 56 termios* IOConsole::originalTerminalSettings_; … … 67 67 68 68 IOConsole::IOConsole() 69 : shell_(Shell::getInstance()) 70 , buffer_(Shell::getInstance().getInputBuffer()) 69 : shell_(new Shell("IOConsole", false)) 70 , buffer_(shell_->getInputBuffer()) 71 , originalTerminalSettings_(new termios()) 71 72 , bStatusPrinted_(false) 72 73 { 73 this->originalTerminalSettings_ = new termios;74 74 this->setTerminalMode(); 75 this->shell_.registerListener(this); 76 75 this->shell_->registerListener(this); 77 76 78 77 // Manually set the widths of the individual status lines 79 this->statusLineWidths_.push_back(20); 78 this->statusLineWidths_.push_back(6); 79 this->statusLineMaxWidth_ = 6; 80 80 } 81 81 … … 86 86 resetTerminalMode(); 87 87 delete this->originalTerminalSettings_; 88 this->shell_->destroy(); 88 89 } 89 90 … … 189 190 this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, '\033', 0)); 190 191 191 // Print input line 192 // Clear screen below the last output line by first moving the cursor to the beginning of the first status line 193 std::cout << "\033[" << (this->bStatusPrinted_ ? this->statusLineWidths_.size() : 0) << "F\033[J"; 194 this->printStatusLines(); 192 195 this->printInputLine(); 193 196 } … … 233 236 // Set cursor to the beginning of the line and erase the line 234 237 std::cout << "\033[1G\033[K"; 235 // Print status line236 //std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, " << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms avg ticktime # ";237 238 // Indicate a command prompt 238 239 std::cout << promptString_g; … … 240 241 std::cout << "\033[s"; 241 242 // Print command line buffer 242 std::cout << this->shell_ .getInput();243 std::cout << this->shell_->getInput(); 243 244 // Restore cursor position and move it to the right 244 245 std::cout << "\033[u"; … … 252 253 if (!this->statusLineWidths_.empty()) 253 254 { 254 if (this->bStatusPrinted_)255 {256 // Erase the status lines first (completely, including new lines!)257 258 }259 255 // Check terminal size 260 /*261 256 int x, y; 262 if (this->getTerminalSize(&x, &y) && (x < statusTextWidth_g || y < (2 + statusTextHeight_g)))257 if (this->getTerminalSize(&x, &y) && (x < (int)this->statusLineMaxWidth_ || y < (int)(this->minOutputLines_ + this->statusLineWidths_.size()))) 263 258 { 264 259 this->bStatusPrinted_ = false; 265 260 return; 266 261 } 267 */ 262 std::cout << "Status" << std::endl; 263 std::cout.flush(); 264 this->bStatusPrinted_ = true; 268 265 } 269 266 } … … 307 304 308 305 IOConsole::IOConsole() 309 : shell_( Shell::getInstance())310 , buffer_( Shell::getInstance().getInputBuffer())306 : shell_(new Shell("IOConsole", false)) 307 , buffer_(shell_->getInputBuffer()) 311 308 { 312 309 this->setTerminalMode(); … … 329 326 } 330 327 331 void IOConsole::print (const std::string& text)328 void IOConsole::printLogText(const std::string& text) 332 329 { 333 330 } … … 360 357 { 361 358 // Save cursor position and move it to the beginning of the first output line 362 std::cout << "\033[s\033[" << (1 + 0/*statusTextHeight_g*/) << "F";359 std::cout << "\033[s\033[" << (1 + this->statusLineWidths_.size()) << "F"; 363 360 // Erase the line 364 361 std::cout << "\033[K"; 365 362 // Reprint the last output line 366 this->printLogText(*(this->shell_ .getNewestLineIterator()));363 this->printLogText(*(this->shell_->getNewestLineIterator())); 367 364 // Restore cursor 368 365 std::cout << "\033[u"; … … 376 373 void IOConsole::lineAdded() 377 374 { 378 // Save cursor and move it to the beginning of the first status line 379 std::cout << "\033[s\033[" << 0/*statusTextHeight_g*/ << "F"; 380 // Create a new line and move cursor to the beginning of it (one cell up) 381 std::cout << std::endl << "\033[1F"; 375 // Move cursor to the beginning of the first status line and erase screen from there 376 std::cout << "\033[" << this->statusLineWidths_.size() << "F\033[J"; 382 377 // Print the new output line 383 this->printLogText(*(this->shell_ .getNewestLineIterator()));384 // Restore cursor (for horizontal position) and move it down again (just in case the lines were shifted)385 std::cout << "\033[u\033[" << (1 + 0/*statusTextHeight_g*/) << "B";386 std::cout.flush();378 this->printLogText(*(this->shell_->getNewestLineIterator())); 379 std::cout << std::endl; 380 this->printStatusLines(); 381 this->printInputLine(); 387 382 } 388 383 … … 414 409 std::cout << "\033[1G"; 415 410 // Print command so the user knows what he has typed 416 std::cout << promptString_g << this->shell_ .getInput() << std::endl;411 std::cout << promptString_g << this->shell_->getInput() << std::endl; 417 412 this->printInputLine(); 418 413 } -
code/branches/console/src/libraries/core/IOConsole.h
r5998 r6004 70 70 void executed(); 71 71 void exit(); 72 Shell &shell_;72 Shell* shell_; 73 73 InputBuffer* buffer_; 74 74 static termios* originalTerminalSettings_; … … 76 76 bool bStatusPrinted_; 77 77 std::vector<unsigned> statusLineWidths_; 78 unsigned int statusLineMaxWidth_; 79 static const unsigned minOutputLines_ = 3; 78 80 79 81 static IOConsole* singletonPtr_s; -
code/branches/console/src/libraries/core/Shell.cc
r5994 r6004 34 34 #include "CoreIncludes.h" 35 35 #include "ConfigValueIncludes.h" 36 #include "Core.h"37 36 #include "ConsoleCommand.h" 38 37 39 38 namespace orxonox 40 39 { 41 SetConsoleCommand(Shell, clearShell, true);42 SetConsoleCommand(Shell, history, true);43 44 40 SetConsoleCommandShortcut(OutputHandler, log); 45 41 SetConsoleCommandShortcut(OutputHandler, error); … … 48 44 SetConsoleCommandShortcut(OutputHandler, debug); 49 45 50 Shell* Shell::singletonPtr_s = 0; 51 52 Shell::Shell() 53 : OutputListener("shell") 46 Shell::Shell(const std::string& consoleName, bool bScrollable) 47 : inputBuffer_(new InputBuffer()) 48 , OutputListener(consoleName) 49 , consoleName_(consoleName) 50 , bScrollable_(bScrollable) 54 51 { 55 52 RegisterRootObject(Shell); … … 63 60 64 61 this->clearLines(); 65 66 this->inputBuffer_ = new InputBuffer();67 62 this->configureInputBuffer(); 68 63 … … 79 74 for (OutputHandler::OutputVectorIterator it = OutputHandler::getInstance().getOutputVectorBegin(); 80 75 it != OutputHandler::getInstance().getOutputVectorEnd(); ++it) 81 this->addLine(it->second, it->first); 76 { 77 if (it->first <= this->getSoftDebugLevel()) 78 { 79 this->outputBuffer_ << it->second; 80 this->outputChanged(it->first); 81 } 82 } 82 83 83 84 // Register the shell as output listener … … 93 94 void Shell::setConfigValues() 94 95 { 95 SetConfigValue Generic(commandHistoryConfigFileType_, maxHistoryLength_, "maxHistoryLength_", "Shell", 100)96 SetConfigValue(maxHistoryLength_, 100) 96 97 .callback(this, &Shell::commandHistoryLengthChanged); 97 SetConfigValue Generic(commandHistoryConfigFileType_, historyOffset_, "historyOffset_", "Shell", 0)98 SetConfigValue(historyOffset_, 0) 98 99 .callback(this, &Shell::commandHistoryOffsetChanged); 99 100 SetConfigValueVectorGeneric(commandHistoryConfigFileType_, commandHistory_, std::vector<std::string>()); … … 104 105 const unsigned int defaultLevel = 3; 105 106 #endif 106 SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevel_, "softDebugLevel Shell", "OutputHandler", defaultLevel)107 SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevel_, "softDebugLevel" + this->consoleName_, "OutputHandler", defaultLevel) 107 108 .description("The maximal level of debug output shown in the Shell"); 108 OutputHandler::getInstance().setSoftDebugLevel("shell",this->softDebugLevel_);109 this->setSoftDebugLevel(this->softDebugLevel_); 109 110 } 110 111 … … 149 150 } 150 151 151 void Shell::clearShell() 152 { 153 Shell::getInstance().clearLines(); 154 } 155 152 /* 156 153 void Shell::history() 157 154 { … … 163 160 instance.addLine(instance.commandHistory_[i], -1); 164 161 } 162 */ 165 163 166 164 void Shell::registerListener(ShellListener* listener) … … 195 193 { 196 194 if (level <= this->softDebugLevel_) 197 this-> lines_.push_front(line);195 this->outputLines_.push_front(line); 198 196 this->updateListeners<&ShellListener::lineAdded>(); 199 197 } … … 201 199 void Shell::clearLines() 202 200 { 203 this-> lines_.clear();204 this->scrollIterator_ = this-> lines_.begin();201 this->outputLines_.clear(); 202 this->scrollIterator_ = this->outputLines_.begin(); 205 203 206 204 this->scrollPosition_ = 0; … … 215 213 return this->scrollIterator_; 216 214 else 217 return this-> lines_.begin();215 return this->outputLines_.begin(); 218 216 } 219 217 220 218 std::list<std::string>::const_iterator Shell::getEndIterator() const 221 219 { 222 return this-> lines_.end();220 return this->outputLines_.end(); 223 221 } 224 222 … … 239 237 } 240 238 241 void Shell::outputChanged() 242 { 243 std::string output; 244 bool newline; 239 void Shell::outputChanged(int level) 240 { 241 bool newline = false; 245 242 do 246 243 { 244 std::string output; 247 245 std::getline(this->outputBuffer_, output); 248 246 … … 261 259 { 262 260 if (this->bAddOutputLevel_) 263 output.insert(0, 1, static_cast<char>( OutputHandler::getInstance().getOutputLevel()));264 265 this-> lines_.push_front(output);261 output.insert(0, 1, static_cast<char>(level)); 262 263 this->outputLines_.push_front(output); 266 264 267 265 if (this->scrollPosition_) 268 266 this->scrollPosition_++; 269 267 else 270 this->scrollIterator_ = this-> lines_.begin();268 this->scrollIterator_ = this->outputLines_.begin(); 271 269 272 270 this->finishedLastLine_ = newline; … … 279 277 else 280 278 { 281 (*this-> lines_.begin()) += output;279 (*this->outputLines_.begin()) += output; 282 280 this->finishedLastLine_ = newline; 283 281 this->updateListeners<&ShellListener::onlyLastLineChanged>(); … … 413 411 void Shell::scroll_up() 414 412 { 415 if (this->scrollIterator_ != this-> lines_.end())413 if (this->scrollIterator_ != this->outputLines_.end()) 416 414 { 417 415 ++this->scrollIterator_; … … 424 422 void Shell::scroll_down() 425 423 { 426 if (this->scrollIterator_ != this-> lines_.begin())424 if (this->scrollIterator_ != this->outputLines_.begin()) 427 425 { 428 426 --this->scrollIterator_; … … 443 441 this->clear(); 444 442 this->scrollPosition_ = 0; 445 this->scrollIterator_ = this-> lines_.begin();443 this->scrollIterator_ = this->outputLines_.begin(); 446 444 447 445 this->updateListeners<&ShellListener::exit>(); -
code/branches/console/src/libraries/core/Shell.h
r5994 r6004 32 32 #include "CorePrereqs.h" 33 33 34 #include <cassert>35 34 #include <list> 36 35 #include <sstream> … … 39 38 40 39 #include "util/OutputHandler.h" 41 #include "input/InputBuffer.h"42 40 #include "OrxonoxClass.h" 43 41 #include "ConfigFileManager.h" 42 #include "input/InputBuffer.h" 44 43 45 44 namespace orxonox … … 62 61 }; 63 62 64 class _CoreExport Shell : public Singleton<Shell>,virtual public OrxonoxClass, public OutputListener63 class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener 65 64 { 66 friend class Singleton<Shell>;67 65 public: 68 Shell( );66 Shell(const std::string& consoleName, bool bScrollable); 69 67 virtual ~Shell(); 70 71 static void clearShell();72 static void history();73 68 74 69 void setConfigValues(); … … 100 95 101 96 inline unsigned int getNumLines() const 102 { return this-> lines_.size(); }97 { return this->outputLines_.size(); } 103 98 inline unsigned int getScrollPosition() const 104 99 { return this->scrollPosition_; } … … 115 110 std::string getFromHistory() const; 116 111 117 virtual void outputChanged( );112 virtual void outputChanged(int level); 118 113 119 114 void inputChanged(); … … 146 141 std::stringstream outputBuffer_; 147 142 bool finishedLastLine_; 148 std::list<std::string> lines_;143 std::list<std::string> outputLines_; 149 144 std::list<std::string>::const_iterator scrollIterator_; 150 145 unsigned int scrollPosition_; 146 unsigned int historyPosition_; 147 bool bAddOutputLevel_; 148 ConfigFileType commandHistoryConfigFileType_; 149 const std::string consoleName_; 150 const bool bScrollable_; 151 152 // Config values 153 unsigned int maxHistoryLength_; 154 unsigned int historyOffset_; 151 155 std::vector<std::string> commandHistory_; 152 unsigned int maxHistoryLength_;153 unsigned int historyPosition_;154 unsigned int historyOffset_;155 bool bAddOutputLevel_;156 156 int softDebugLevel_; 157 158 ConfigFileType commandHistoryConfigFileType_;159 160 static Shell* singletonPtr_s;161 157 }; 162 158 }
Note: See TracChangeset
for help on using the changeset viewer.