|
4 | 4 | import '../common/index.mjs';
|
5 | 5 | import assert from 'assert';
|
6 | 6 | import { Readline } from 'readline/promises';
|
| 7 | +import { setImmediate } from 'timers/promises'; |
7 | 8 | import { Writable } from 'stream';
|
8 | 9 |
|
9 | 10 | import utils from 'internal/readline/utils';
|
@@ -161,3 +162,65 @@ class TestWritable extends Writable {
|
161 | 162 |
|
162 | 163 | await assert.rejects(readline.cursorTo(1).commit(), error);
|
163 | 164 | }
|
| 165 | + |
| 166 | +{ |
| 167 | + const writable = new TestWritable(); |
| 168 | + const readline = new Readline(writable, { autoCommit: true }); |
| 169 | + |
| 170 | + await readline.clearScreenDown(); |
| 171 | + await setImmediate(); // Wait for next tick as auto commit is asynchronous. |
| 172 | + assert.deepStrictEqual(writable.data, CSI.kClearScreenDown); |
| 173 | +} |
| 174 | + |
| 175 | +{ |
| 176 | + const writable = new TestWritable(); |
| 177 | + const readline = new Readline(writable, { autoCommit: true }); |
| 178 | + for (const [dir, data] of |
| 179 | + [ |
| 180 | + [-1, CSI.kClearToLineBeginning], |
| 181 | + [1, CSI.kClearToLineEnd], |
| 182 | + [0, CSI.kClearLine], |
| 183 | + ]) { |
| 184 | + writable.data = ''; |
| 185 | + readline.clearLine(dir); |
| 186 | + await setImmediate(); // Wait for next tick as auto commit is asynchronous. |
| 187 | + assert.deepStrictEqual(writable.data, data); |
| 188 | + } |
| 189 | +} |
| 190 | + |
| 191 | +{ |
| 192 | + const writable = new TestWritable(); |
| 193 | + const readline = new Readline(writable, { autoCommit: true }); |
| 194 | + for (const [x, y, data] of |
| 195 | + [ |
| 196 | + [0, 0, ''], |
| 197 | + [1, 0, '\x1b[1C'], |
| 198 | + [-1, 0, '\x1b[1D'], |
| 199 | + [0, 1, '\x1b[1B'], |
| 200 | + [0, -1, '\x1b[1A'], |
| 201 | + [1, 1, '\x1b[1C\x1b[1B'], |
| 202 | + [-1, 1, '\x1b[1D\x1b[1B'], |
| 203 | + [-1, -1, '\x1b[1D\x1b[1A'], |
| 204 | + [1, -1, '\x1b[1C\x1b[1A'], |
| 205 | + ]) { |
| 206 | + writable.data = ''; |
| 207 | + readline.moveCursor(x, y); |
| 208 | + await setImmediate(); // Wait for next tick as auto commit is asynchronous. |
| 209 | + assert.deepStrictEqual(writable.data, data); |
| 210 | + } |
| 211 | +} |
| 212 | + |
| 213 | +{ |
| 214 | + const writable = new TestWritable(); |
| 215 | + const readline = new Readline(writable, { autoCommit: true }); |
| 216 | + for (const [x, y, data] of |
| 217 | + [ |
| 218 | + [1, undefined, '\x1b[2G'], |
| 219 | + [1, 2, '\x1b[3;2H'], |
| 220 | + ]) { |
| 221 | + writable.data = ''; |
| 222 | + readline.cursorTo(x, y); |
| 223 | + await setImmediate(); // Wait for next tick as auto commit is asynchronous. |
| 224 | + assert.deepStrictEqual(writable.data, data); |
| 225 | + } |
| 226 | +} |
0 commit comments