Changeset 5975
- Timestamp:
- Oct 21, 2009, 9:26:35 AM (15 years ago)
- Location:
- code/branches/console/src/libraries/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/libraries/core/IOConsole.cc
r5974 r5975 57 57 IOConsole::IOConsole() 58 58 : shell_(Shell::getInstance()) 59 , bEscapeMode_(false)59 , escapeMode_(None) 60 60 , buffer_(Shell::getInstance().getInputBuffer()) 61 61 { … … 95 95 void IOConsole::update(const Clock& time) 96 96 { 97 unsigned char c ;97 unsigned char c = 0; 98 98 while (read(STDIN_FILENO, &c, 1) == 1) 99 99 { 100 if (this->bEscapeMode_) 100 if (this->escapeMode_ == First && c == '[') 101 this->escapeMode_ = Second; 102 // Get Alt+Tab combination when switching applications 103 else if (this->escapeMode_ == First && c == '\t') 101 104 { 102 this->escapeSequence_ += c; 105 this->buffer_->buttonPressed(KeyEvent(KeyCode::Tab, '\t', KeyboardModifier::Alt)); 106 this->escapeMode_ = None; 107 } 108 else if (this->escapeMode_ == Second) 109 { 103 110 bool endOfSeq = true; 104 if (this->escapeSequence_ == "[A") 111 this->escapeMode_ = None; 112 if (this->escapeSequence_ == "A") 105 113 this->buffer_->buttonPressed(KeyEvent(KeyCode::Up, 0, 0)); 106 else if (this->escapeSequence_ == " [B")114 else if (this->escapeSequence_ == "B") 107 115 this->buffer_->buttonPressed(KeyEvent(KeyCode::Down, 0, 0)); 108 else if (this->escapeSequence_ == " [C")116 else if (this->escapeSequence_ == "C") 109 117 this->buffer_->buttonPressed(KeyEvent(KeyCode::Right, 0, 0)); 110 else if (this->escapeSequence_ == " [D")118 else if (this->escapeSequence_ == "D") 111 119 this->buffer_->buttonPressed(KeyEvent(KeyCode::Left, 0, 0)); 112 else if (this->escapeSequence_ == " [1~")120 else if (this->escapeSequence_ == "1~") 113 121 this->buffer_->buttonPressed(KeyEvent(KeyCode::Home, 0, 0)); 114 else if (this->escapeSequence_ == " [2~")122 else if (this->escapeSequence_ == "2~") 115 123 this->buffer_->buttonPressed(KeyEvent(KeyCode::Insert, 0, 0)); 116 else if (this->escapeSequence_ == " [3~")124 else if (this->escapeSequence_ == "3~") 117 125 this->buffer_->buttonPressed(KeyEvent(KeyCode::Delete, 0, 0)); 118 else if (this->escapeSequence_ == " [4~")126 else if (this->escapeSequence_ == "4~") 119 127 this->buffer_->buttonPressed(KeyEvent(KeyCode::End, 0, 0)); 120 else if (this->escapeSequence_ == " [5~")128 else if (this->escapeSequence_ == "5~") 121 129 this->buffer_->buttonPressed(KeyEvent(KeyCode::PageUp, 0, 0)); 122 else if (this->escapeSequence_ == " [6~")130 else if (this->escapeSequence_ == "6~") 123 131 this->buffer_->buttonPressed(KeyEvent(KeyCode::PageDown, 0, 0)); 124 // Get Alt+Tab combination when switching applications125 else if (this->escapeSequence_ == "\t")126 this->buffer_->buttonPressed(KeyEvent(KeyCode::Tab, '\t', KeyboardModifier::Alt));127 132 else if (this->escapeSequence_.size() > 4) 128 endOfSeq = true; // Something went wrong, start over 133 // User probably very quickly pressed ESC and [ 134 this->escapeMode_ = None; 129 135 else 130 endOfSeq = false; 131 132 //this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, 0, 0)); 133 134 if (endOfSeq) 135 this->bEscapeMode_ = false; 136 // Waiting for sequence to complete 137 this->escapeMode_ = Second; 136 138 } 137 else // not in an escape sequence 139 else // not in an escape sequence OR user might have pressed just ESC 138 140 { 141 if (this->escapeMode_ == First) 142 { 143 this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, 0, 0)); 144 this->escapeMode_ = None; 145 } 139 146 if (c == '\033') 140 141 this-> bEscapeMode_ = true;142 143 147 { 148 this->escapeMode_ = First; 149 this->escapeSequence_.clear(); 150 } 144 151 else 145 152 { … … 163 170 } 164 171 165 // Print input line 166 this->printInputLine(); 172 // If there is still an escape key pending (escape key ONLY), then 173 // it sure isn't an escape sequence here 174 this->buffer_->buttonPressed(KeyEvent(KeyCode::Escape, 0, 0)); 175 176 // Print input line 177 this->printInputLine(); 167 178 } 168 179 169 180 void IOConsole::printOutputLine(const std::string& line) 170 181 { 171 182 COUT(0) << "print output" << std::endl; 172 183 // Save cursor position 173 184 std::cout << "\033[s"; … … 206 217 std::cout.flush(); 207 218 208 219 this->printInputLine(); 209 220 } 210 221 … … 215 226 // print status line 216 227 //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 # "; 217 218 228 // Show an arrow to indicate a command prompt 229 std::cout << ">"; 219 230 // save cursor position 220 231 std::cout << "\033[s"; -
code/branches/console/src/libraries/core/IOConsole.h
r5973 r5975 53 53 54 54 private: 55 enum EscapeMode 56 { 57 None, 58 First, 59 Second 60 }; 61 55 62 void setTerminalMode(); 56 63 static void resetTerminalMode(); … … 68 75 69 76 Shell& shell_; 70 bool bEscapeMode_;77 EscapeMode escapeMode_; 71 78 std::string escapeSequence_; 72 79 InputBuffer* buffer_;
Note: See TracChangeset
for help on using the changeset viewer.