Skip to content
Permalink
Browse files

readline: establish y in cursorTo as optional

Parameter y in cursorTo() is optional and this is also verified by
tests but docs don't state this. Besides that if the newly added
parameter callback is used with no y, it's quite unhandy. This PR allows
to simply omit y.

PR-URL: #29128
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information...
Flarna authored and targos committed Aug 14, 2019
1 parent e51f924 commit e474c6776c4103ad1d48c8f58444bcf294980f51
Showing with 15 additions and 2 deletions.
  1. +1 −1 doc/api/readline.md
  2. +1 −1 doc/api/tty.md
  3. +5 −0 lib/readline.js
  4. +8 −0 test/parallel/test-readline-csi.js
@@ -487,7 +487,7 @@ function completer(linePartial, callback) {
}
```

## readline.cursorTo(stream, x, y[, callback])
## readline.cursorTo(stream, x[, y][, callback])
<!-- YAML
added: v0.7.7
changes:
@@ -145,7 +145,7 @@ added: v0.7.7
A `number` specifying the number of columns the TTY currently has. This property
is updated whenever the `'resize'` event is emitted.

### writeStream.cursorTo(x, y[, callback])
### writeStream.cursorTo(x[, y][, callback])
<!-- YAML
added: v0.7.7
changes:
@@ -1193,6 +1193,11 @@ function cursorTo(stream, x, y, callback) {
if (callback !== undefined && typeof callback !== 'function')
throw new ERR_INVALID_CALLBACK(callback);

if (typeof y === 'function') {
callback = y;
y = undefined;
}

if (stream == null || (typeof x !== 'number' && typeof y !== 'number')) {
if (typeof callback === 'function')
process.nextTick(callback);
@@ -133,6 +133,10 @@ writable.data = '';
assert.strictEqual(readline.cursorTo(writable, 1, 'a'), true);
assert.strictEqual(writable.data, '\x1b[2G');

writable.data = '';
assert.strictEqual(readline.cursorTo(writable, 1), true);
assert.strictEqual(writable.data, '\x1b[2G');

writable.data = '';
assert.strictEqual(readline.cursorTo(writable, 1, 2), true);
assert.strictEqual(writable.data, '\x1b[3;2H');
@@ -141,6 +145,10 @@ writable.data = '';
assert.strictEqual(readline.cursorTo(writable, 1, 2, common.mustCall()), true);
assert.strictEqual(writable.data, '\x1b[3;2H');

writable.data = '';
assert.strictEqual(readline.cursorTo(writable, 1, common.mustCall()), true);
assert.strictEqual(writable.data, '\x1b[2G');

// Verify that cursorTo() throws on invalid callback.
assert.throws(() => {
readline.cursorTo(writable, 1, 1, null);

0 comments on commit e474c67

Please sign in to comment.
You can’t perform that action at this time.