(stream)
| 84 | - two leading ESCs apparently mean the same as one leading ESC |
| 85 | */ |
| 86 | function* emitKeys(stream) { |
| 87 | while (true) { |
| 88 | let ch = yield; |
| 89 | let s = ch; |
| 90 | let escaped = false; |
| 91 | const key = { |
| 92 | sequence: null, |
| 93 | name: undefined, |
| 94 | ctrl: false, |
| 95 | meta: false, |
| 96 | shift: false, |
| 97 | }; |
| 98 | |
| 99 | if (ch === kEscape) { |
| 100 | escaped = true; |
| 101 | s += (ch = yield); |
| 102 | |
| 103 | if (ch === kEscape) { |
| 104 | s += (ch = yield); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if (escaped && (ch === 'O' || ch === '[')) { |
| 109 | // ANSI escape sequence |
| 110 | let code = ch; |
| 111 | let modifier = 0; |
| 112 | |
| 113 | if (ch === 'O') { |
| 114 | // ESC O letter |
| 115 | // ESC O modifier letter |
| 116 | s += (ch = yield); |
| 117 | |
| 118 | if (ch >= '0' && ch <= '9') { |
| 119 | modifier = (ch >> 0) - 1; |
| 120 | s += (ch = yield); |
| 121 | } |
| 122 | |
| 123 | code += ch; |
| 124 | } else if (ch === '[') { |
| 125 | // ESC [ letter |
| 126 | // ESC [ modifier letter |
| 127 | // ESC [ [ modifier letter |
| 128 | // ESC [ [ num char |
| 129 | s += (ch = yield); |
| 130 | |
| 131 | if (ch === '[') { |
| 132 | // \x1b[[A |
| 133 | // ^--- escape codes might have a second bracket |
| 134 | code += ch; |
| 135 | s += (ch = yield); |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * Here and later we try to buffer just enough data to get |
| 140 | * a complete ascii sequence. |
| 141 | * |
| 142 | * We have basically two classes of ascii characters to process: |
| 143 | * |
no test coverage detected
searching dependent graphs…