| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7611d5b commit 925dd8e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -132,11 +132,19 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 132 | 132 | let previewCompletionCounter = 0; | |
| 133 | 133 | let completionPreview = null; | |
| 134 | 134 | ||
| 135 | + function getPreviewPos() { | ||
| 136 | + const displayPos = repl._getDisplayPos(`${repl._prompt}${repl.line}`); | ||
| 137 | + const cursorPos = repl._getCursorPos(); | ||
| 138 | + const rows = 1 + displayPos.rows - cursorPos.rows; | ||
| 139 | + return { rows, cols: cursorPos.cols }; | ||
| 140 | + } | ||
| 141 | + | ||
| 135 | 142 | const clearPreview = () => { | |
| 136 | 143 | if (inputPreview !== null) { | |
| 137 | - moveCursor(repl.output, 0, 1); | ||
| 144 | + const { rows } = getPreviewPos(); | ||
| 145 | + moveCursor(repl.output, 0, rows); | ||
| 138 | 146 | clearLine(repl.output); | |
| 139 | - moveCursor(repl.output, 0, -1); | ||
| 147 | + moveCursor(repl.output, 0, -rows); | ||
| 140 | 148 | lastInputPreview = inputPreview; | |
| 141 | 149 | inputPreview = null; | |
| 142 | 150 | } | |
@@ -280,16 +288,6 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 280 | 288 | return; | |
| 281 | 289 | } | |
| 282 | 290 | ||
| 283 | - // Do not show previews in case the current line is longer than the column | ||
| 284 | - // width. | ||
| 285 | - // TODO(BridgeAR): Fix me. This should not be necessary. It currently breaks | ||
| 286 | - // the output though. We also have to check for characters that have more | ||
| 287 | - // than a single byte as length. Check Interface.prototype._moveCursor. It | ||
| 288 | - // contains the necessary logic. | ||
| 289 | - if (repl.line.length + repl._prompt.length > repl.columns) { | ||
| 290 | - return; | ||
| 291 | - } | ||
| 292 | - | ||
| 293 | 291 | // Add the autocompletion preview. | |
| 294 | 292 | // TODO(BridgeAR): Trigger the input preview after the completion preview. | |
| 295 | 293 | // That way it's possible to trigger the input prefix including the | |
@@ -344,9 +342,12 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 344 | 342 | `\u001b[90m${inspected}\u001b[39m` : | |
| 345 | 343 | `// ${inspected}`; | |
| 346 | 344 | ||
| 345 | + const { rows: previewRows, cols: cursorCols } = getPreviewPos(); | ||
| 346 | + if (previewRows !== 1) | ||
| 347 | + moveCursor(repl.output, 0, previewRows - 1); | ||
| 348 | + const { cols: resultCols } = repl._getDisplayPos(result); | ||
| 347 | 349 | repl.output.write(`\n${result}`); | |
| 348 | - moveCursor(repl.output, 0, -1); | ||
| 349 | - cursorTo(repl.output, repl._prompt.length + repl.cursor); | ||
| 350 | + moveCursor(repl.output, cursorCols - resultCols, -previewRows); | ||
| 350 | 351 | }); | |
| 351 | 352 | }; | |
| 352 | 353 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,7 +108,7 @@ const tests = [ | |||
| 108 | 108 | env: { NODE_REPL_HISTORY: defaultHistoryPath }, | |
| 109 | 109 | skip: !process.features.inspector, | |
| 110 | 110 | test: [ | |
| 111 | - `const ${'veryLongName'.repeat(30)} = 'I should not be previewed'`, | ||
| 111 | + `const ${'veryLongName'.repeat(30)} = 'I should be previewed'`, | ||
| 112 | 112 | ENTER, | |
| 113 | 113 | 'const e = new RangeError("visible\\ninvisible")', | |
| 114 | 114 | ENTER, | |
@@ -127,27 +127,70 @@ const tests = [ | |||
| 127 | 127 | { | |
| 128 | 128 | env: { NODE_REPL_HISTORY: defaultHistoryPath }, | |
| 129 | 129 | columns: 250, | |
| 130 | + showEscapeCodes: true, | ||
| 130 | 131 | skip: !process.features.inspector, | |
| 131 | 132 | test: [ | |
| 132 | 133 | UP, | |
| 133 | 134 | UP, | |
| 134 | 135 | UP, | |
| 136 | + WORD_LEFT, | ||
| 135 | 137 | UP, | |
| 136 | 138 | BACKSPACE | |
| 137 | 139 | ], | |
| 140 | + // A = Cursor n up | ||
| 141 | + // B = Cursor n down | ||
| 142 | + // C = Cursor n forward | ||
| 143 | + // D = Cursor n back | ||
| 144 | + // G = Cursor to column n | ||
| 145 | + // J = Erase in screen; 0 = right; 1 = left; 2 = total | ||
| 146 | + // K = Erase in line; 0 = right; 1 = left; 2 = total | ||
| 138 | 147 | expected: [ | |
| 139 | - prompt, | ||
| 148 | + // 0. Start | ||
| 149 | + '\x1B[1G', '\x1B[0J', | ||
| 150 | + prompt, '\x1B[3G', | ||
| 151 | + // 1. UP | ||
| 140 | 152 | // This exceeds the maximum columns (250): | |
| 141 | 153 | // Whitespace + prompt + ' // '.length + 'function'.length | |
| 142 | 154 | // 236 + 2 + 4 + 8 | |
| 143 | - `${prompt}${' '.repeat(236)} fun`, | ||
| 144 | - `${prompt}${' '.repeat(235)} fun`, | ||
| 145 | - ' // ction', | ||
| 146 | - ' // ction', | ||
| 147 | - `${prompt}${'veryLongName'.repeat(30)}`, | ||
| 148 | - `${prompt}e`, | ||
| 149 | - '\n// RangeError: visible', | ||
| 150 | - prompt | ||
| 155 | + '\x1B[1G', '\x1B[0J', | ||
| 156 | + `${prompt}${' '.repeat(236)} fun`, '\x1B[243G', | ||
| 157 | + // 2. UP | ||
| 158 | + '\x1B[1G', '\x1B[0J', | ||
| 159 | + `${prompt}${' '.repeat(235)} fun`, '\x1B[242G', | ||
| 160 | + // TODO(BridgeAR): Investigate why the preview is generated twice. | ||
| 161 | + ' // ction', '\x1B[242G', | ||
| 162 | + ' // ction', '\x1B[242G', | ||
| 163 | + // Preview cleanup | ||
| 164 | + '\x1B[0K', | ||
| 165 | + // 3. UP | ||
| 166 | + '\x1B[1G', '\x1B[0J', | ||
| 167 | + // 'veryLongName'.repeat(30).length === 360 | ||
| 168 | + // prompt.length === 2 | ||
| 169 | + // 360 % 250 + 2 === 112 (+1) | ||
| 170 | + `${prompt}${'veryLongName'.repeat(30)}`, '\x1B[113G', | ||
| 171 | + // "// 'I should be previewed'".length + 86 === 112 (+1) | ||
| 172 | + "\n// 'I should be previewed'", '\x1B[86C\x1B[1A', | ||
| 173 | + // Preview cleanup | ||
| 174 | + '\x1B[1B', '\x1B[2K', '\x1B[1A', | ||
| 175 | + // 4. WORD LEFT | ||
| 176 | + // Almost identical as above. Just one extra line. | ||
| 177 | + // Math.floor(360 / 250) === 1 | ||
| 178 | + '\x1B[1A', | ||
| 179 | + '\x1B[1G', '\x1B[0J', | ||
| 180 | + `${prompt}${'veryLongName'.repeat(30)}`, '\x1B[3G', '\x1B[1A', | ||
| 181 | + '\x1B[1B', "\n// 'I should be previewed'", '\x1B[24D\x1B[2A', | ||
| 182 | + // Preview cleanup | ||
| 183 | + '\x1B[2B', '\x1B[2K', '\x1B[2A', | ||
| 184 | + // 5. UP | ||
| 185 | + '\x1B[1G', '\x1B[0J', | ||
| 186 | + `${prompt}e`, '\x1B[4G', | ||
| 187 | + // '// RangeError: visible'.length - 19 === 3 (+1) | ||
| 188 | + '\n// RangeError: visible', '\x1B[19D\x1B[1A', | ||
| 189 | + // Preview cleanup | ||
| 190 | + '\x1B[1B', '\x1B[2K', '\x1B[1A', | ||
| 191 | + // 6. Backspace | ||
| 192 | + '\x1B[1G', '\x1B[0J', | ||
| 193 | + prompt, '\x1B[3G' | ||
| 151 | 194 | ], | |
| 152 | 195 | clean: true | |
| 153 | 196 | }, | |
@@ -169,11 +212,11 @@ const tests = [ | |||
| 169 | 212 | WORD_RIGHT, | |
| 170 | 213 | ENTER | |
| 171 | 214 | ], | |
| 172 | - // C = Cursor forward | ||
| 173 | - // D = Cursor back | ||
| 215 | + // C = Cursor n forward | ||
| 216 | + // D = Cursor n back | ||
| 174 | 217 | // G = Cursor to column n | |
| 175 | - // J = Erase in screen | ||
| 176 | - // K = Erase in line | ||
| 218 | + // J = Erase in screen; 0 = right; 1 = left; 2 = total | ||
| 219 | + // K = Erase in line; 0 = right; 1 = left; 2 = total | ||
| 177 | 220 | expected: [ | |
| 178 | 221 | // 0. | |
| 179 | 222 | // 'f' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,12 +68,12 @@ async function tests(options) { | |||
| 68 | 68 | const testCases = [ | |
| 69 | 69 | ['foo', [2, 4], '[Function: foo]', | |
| 70 | 70 | 'foo', | |
| 71 | - '\x1B[90m[Function: foo]\x1B[39m\x1B[1A\x1B[11G\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 71 | + '\x1B[90m[Function: foo]\x1B[39m\x1B[5D\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 72 | 72 | '\x1B[36m[Function: foo]\x1B[39m', | |
| 73 | 73 | '\x1B[1G\x1B[0Jrepl > \x1B[8G'], | |
| 74 | 74 | ['koo', [2, 4], '[Function: koo]', | |
| 75 | 75 | 'k\x1B[90moo\x1B[39m\x1B[9G\x1B[0Ko\x1B[90mo\x1B[39m\x1B[10G\x1B[0Ko', | |
| 76 | - '\x1B[90m[Function: koo]\x1B[39m\x1B[1A\x1B[11G\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 76 | + '\x1B[90m[Function: koo]\x1B[39m\x1B[5D\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 77 | 77 | '\x1B[36m[Function: koo]\x1B[39m', | |
| 78 | 78 | '\x1B[1G\x1B[0Jrepl > \x1B[8G'], | |
| 79 | 79 | ['a', [1, 2], undefined], | |
@@ -83,19 +83,19 @@ async function tests(options) { | |||
| 83 | 83 | '\x1B[1G\x1B[0Jrepl > \x1B[8G'], | |
| 84 | 84 | ['1n + 2n', [2, 5], '\x1B[33m3n\x1B[39m', | |
| 85 | 85 | '1n + 2', | |
| 86 | - '\x1B[90mType[39m\x1B[1A\x1B[14G\x1B[1B\x1B[2K\x1B[1An', | ||
| 87 | - '\x1B[90m3n\x1B[39m\x1B[1A\x1B[15G\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 86 | + '\x1B[90mType[39m\x1B[57D\x1B[1A\x1B[1B\x1B[2K\x1B[1An', | ||
| 87 | + '\x1B[90m3n\x1B[39m\x1B[12C\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 88 | 88 | '\x1B[33m3n\x1B[39m', | |
| 89 | 89 | '\x1B[1G\x1B[0Jrepl > \x1B[8G'], | |
| 90 | 90 | ['{ a: true };', [2, 4], '\x1B[33mtrue\x1B[39m', | |
| 91 | 91 | '{ a: tru\x1B[90me\x1B[39m\x1B[16G\x1B[0Ke };', | |
| 92 | - '\x1B[90mtrue\x1B[39m\x1B[1A\x1B[20G\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 92 | + '\x1B[90mtrue\x1B[39m\x1B[15C\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 93 | 93 | '\x1B[33mtrue\x1B[39m', | |
| 94 | 94 | '\x1B[1G\x1B[0Jrepl > \x1B[8G'], | |
| 95 | 95 | [' \t { a: true};', [2, 5], '\x1B[33mtrue\x1B[39m', | |
| 96 | 96 | ' \t { a: tru\x1B[90me\x1B[39m\x1B[19G\x1B[0Ke}', | |
| 97 | - '\x1B[90m{ a: true }\x1B[39m\x1B[1A\x1B[21G\x1B[1B\x1B[2K\x1B[1A;', | ||
| 98 | - '\x1B[90mtrue\x1B[39m\x1B[1A\x1B[22G\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 97 | + '\x1B[90m{ a: true }\x1B[39m\x1B[8C\x1B[1A\x1B[1B\x1B[2K\x1B[1A;', | ||
| 98 | + '\x1B[90mtrue\x1B[39m\x1B[16C\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 99 | 99 | '\x1B[33mtrue\x1B[39m', | |
| 100 | 100 | '\x1B[1G\x1B[0Jrepl > \x1B[8G'] | |
| 101 | 101 | ]; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments