Changeset 5983 for code/branches/console/src
- Timestamp:
- Oct 21, 2009, 10:25:59 PM (15 years ago)
- Location:
- code/branches/console/src/libraries
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/libraries/core/IOConsole.cc
r5975 r5983 62 62 this->originalTerminalSettings_ = new termios; 63 63 this->setTerminalMode(); 64 this->shell_.registerListener(this); 64 65 } 65 66 … … 70 71 resetTerminalMode(); 71 72 delete this->originalTerminalSettings_; 72 COUT(0) << "Press enter to end the game..." << std::endl;73 73 } 74 74 … … 108 108 else if (this->escapeMode_ == Second) 109 109 { 110 bool endOfSeq = true;110 this->escapeSequence_ += c; 111 111 this->escapeMode_ = None; 112 112 if (this->escapeSequence_ == "A") … … 141 141 if (this->escapeMode_ == First) 142 142 { 143 this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, 0, 0));143 this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, c, 0)); 144 144 this->escapeMode_ = None; 145 145 } … … 172 172 // If there is still an escape key pending (escape key ONLY), then 173 173 // it sure isn't an escape sequence here 174 this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, 0, 0)); 174 if (this->escapeMode_ == First) 175 this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, '\033', 0)); 176 // Reset in any case because escape sequences always come in one piece 177 this->escapeMode_ = None; 175 178 176 179 // Print input line … … 178 181 } 179 182 180 void IOConsole::printOutputLine(const std::string& line) 181 { 182 COUT(0) << "print output" << std::endl; 183 // Save cursor position 184 std::cout << "\033[s"; 185 183 void IOConsole::print(const std::string& text) 184 { 186 185 std::string output; 187 186 188 187 // Handle line colouring by inspecting the first letter 189 188 char level = 0; 190 if (! line.empty())191 level = line[0];189 if (!text.empty()) 190 level = text[0]; 192 191 if (level >= -1 && level <= 6) 193 output = line.substr(1);192 output = text.substr(1); 194 193 else 195 output = line;194 output = text; 196 195 197 196 // Colour line 198 197 switch (level) 199 198 { 200 case -1: std::cout << "\033[3 0m"; break;199 case -1: std::cout << "\033[37m"; break; 201 200 case 1: std::cout << "\033[91m"; break; 202 201 case 2: std::cout << "\033[31m"; break; … … 209 208 210 209 // Print output line 211 std::cout << output << std::endl; 212 213 // Reset colour to black 214 std::cout << "\033[30m"; 215 // Restore cursor position 216 std::cout << "\033[u"; 210 std::cout << output; 211 212 // Reset colour to white 213 std::cout << "\033[37m"; 217 214 std::cout.flush(); 218 219 this->printInputLine();220 215 } 221 216 … … 223 218 { 224 219 // set cursor to the beginning of the line and erase the line 225 std::cout << "\033[ 0G\033[K";220 std::cout << "\033[1G\033[K"; 226 221 // print status line 227 222 //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 # "; 228 223 // Show an arrow to indicate a command prompt 229 std::cout << " >";224 std::cout << "orxonox>"; 230 225 // save cursor position 231 226 std::cout << "\033[s"; … … 261 256 void IOConsole::onlyLastLineChanged() 262 257 { 263 // We cannot do anything here because printed lines are fixed 264 COUT(2) << "Warning: Trying to edit last console lines, which is impossible!" << std::endl; 258 // Save cursor position and move it the beginning of the second to last line 259 std::cout << "\033[s\033[1F"; 260 // Erase the second to last line 261 std::cout << "\033[K"; 262 this->print(*(this->shell_.getNewestLineIterator())); 263 // Restore cursor 264 std::cout << "\033[u"; 265 std::cout.flush(); 265 266 } 266 267 … … 271 272 void IOConsole::lineAdded() 272 273 { 273 this->printOutputLine(*(this->shell_.getNewestLineIterator())); 274 // Move curosr the beginning of the line and erase it 275 std::cout << "\033[1G\033[K"; 276 this->print(*(this->shell_.getNewestLineIterator())); 277 std::cout << std::endl; 278 this->printInputLine(); 274 279 } 275 280 … … 294 299 /** 295 300 @brief 301 Called if a command is about to be executed 302 */ 303 void IOConsole::executed() 304 { 305 // Move curosr the beginning of the line 306 std::cout << "\033[1G"; 307 // Print command so the user knows what he typed 308 std::cout << "orxonox>" << this->shell_.getInput() << std::endl; 309 this->printInputLine(); 310 } 311 312 313 /** 314 @brief 296 315 Called if the console gets closed. 297 316 */ -
code/branches/console/src/libraries/core/IOConsole.h
r5975 r5983 63 63 static void resetTerminalMode(); 64 64 65 void print OutputLine(const std::string& line);65 void print(const std::string& line); 66 66 void printInputLine(); 67 67 … … 72 72 void inputChanged(); 73 73 void cursorChanged(); 74 void executed(); 74 75 void exit(); 75 76 -
code/branches/console/src/libraries/core/Shell.cc
r5973 r5983 121 121 this->inputBuffer_->registerListener(this, &Shell::hintandcomplete, '\t', true); 122 122 this->inputBuffer_->registerListener(this, &Shell::backspace, '\b', true); 123 this->inputBuffer_->registerListener(this, &Shell::backspace, static_cast<char>(127), true);123 this->inputBuffer_->registerListener(this, &Shell::backspace, '\177', true); 124 124 this->inputBuffer_->registerListener(this, &Shell::deletechar, KeyCode::Delete); 125 this->inputBuffer_->registerListener(this, &Shell::exit, static_cast<char>(27), true);125 this->inputBuffer_->registerListener(this, &Shell::exit, '\033', true); // escape 126 126 this->inputBuffer_->registerListener(this, &Shell::cursor_right, KeyCode::Right); 127 127 this->inputBuffer_->registerListener(this, &Shell::cursor_left, KeyCode::Left); … … 278 278 { 279 279 this->addToHistory(this->inputBuffer_->get()); 280 this-> addLine(this->inputBuffer_->get(), 0);280 this->updateListeners<&ShellListener::executed>(); 281 281 282 282 if (!CommandExecutor::execute(this->inputBuffer_->get())) -
code/branches/console/src/libraries/core/Shell.h
r5969 r5983 57 57 virtual void inputChanged() {} 58 58 virtual void cursorChanged() {} 59 virtual void executed() {} 59 60 virtual void exit() {} 60 61 }; -
code/branches/console/src/libraries/util/OutputHandler.cc
r5738 r5983 149 149 OutputHandler& OutputHandler::operator<<(std::streambuf* sb) 150 150 { 151 if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)152 std::cout << sb;151 //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_) 152 // std::cout << sb; 153 153 154 154 if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_) … … 171 171 OutputHandler& OutputHandler::operator<<(std::ostream& (*manipulator)(std::ostream&)) 172 172 { 173 if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)174 manipulator(std::cout);173 //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_) 174 // manipulator(std::cout); 175 175 176 176 if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_) … … 193 193 OutputHandler& OutputHandler::operator<<(std::ios& (*manipulator)(std::ios&)) 194 194 { 195 if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)196 manipulator(std::cout);195 //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_) 196 // manipulator(std::cout); 197 197 198 198 if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_) … … 215 215 OutputHandler& OutputHandler::operator<<(std::ios_base& (*manipulator)(std::ios_base&)) 216 216 { 217 if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)218 manipulator(std::cout);217 //if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_) 218 // manipulator(std::cout); 219 219 220 220 if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_) -
code/branches/console/src/libraries/util/OutputHandler.h
r5738 r5983 164 164 OutputHandler& OutputHandler::output(const T& output) 165 165 { 166 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)167 std::cout << output;166 //if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_) 167 // std::cout << output; 168 168 169 169 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_) … … 188 188 OutputHandler& operator<<(OutputHandler& out, const T& output) 189 189 { 190 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= out.getOutputLevel())191 std::cout << output;190 //if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= out.getOutputLevel()) 191 // std::cout << output; 192 192 193 193 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= out.getOutputLevel())
Note: See TracChangeset
for help on using the changeset viewer.