| 25 | } |
| 26 | |
| 27 | LineBufferBase::Action LineBufferBase::processKey(char key, ReadWriteStream* output) |
| 28 | { |
| 29 | auto prevKey = previousKey; |
| 30 | previousKey = key; |
| 31 | |
| 32 | switch(key) { |
| 33 | case '\x1b': // ESC -> delete current commandLine |
| 34 | clear(); |
| 35 | if(output) { |
| 36 | output->println(); |
| 37 | } |
| 38 | return Action::clear; |
| 39 | |
| 40 | case '\b': // delete (backspace) |
| 41 | case '\x7f': // xterm ctrl-? |
| 42 | if(!backspace()) { |
| 43 | return Action::none; |
| 44 | } |
| 45 | if(output) { |
| 46 | output->print("\b \b"); |
| 47 | } |
| 48 | return Action::backspace; |
| 49 | |
| 50 | case '\r': |
| 51 | case '\n': |
| 52 | // For "\r\n" or "\n\r" sequence ignore second key |
| 53 | if(prevKey != key && (prevKey == '\r' || prevKey == '\n')) { |
| 54 | previousKey = '\0'; |
| 55 | return Action::none; |
| 56 | } |
| 57 | if(output) { |
| 58 | output->println(); |
| 59 | } |
| 60 | return Action::submit; |
| 61 | |
| 62 | default: |
| 63 | if(!addChar(key)) { |
| 64 | return Action::none; |
| 65 | } |
| 66 | if(output) { |
| 67 | output->print(key); |
| 68 | } |
| 69 | return Action::echo; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | char LineBufferBase::addChar(char c) |
| 74 | { |