Skip to content

Commit e474c67

Browse files
Flarnatargos
authored andcommitted
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent e51f924 commit e474c67

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

doc/api/readline.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ function completer(linePartial, callback) {
487487
}
488488
```
489489

490-
## readline.cursorTo(stream, x, y[, callback])
490+
## readline.cursorTo(stream, x[, y][, callback])
491491
<!-- YAML
492492
added: v0.7.7
493493
changes:

doc/api/tty.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ added: v0.7.7
145145
A `number` specifying the number of columns the TTY currently has. This property
146146
is updated whenever the `'resize'` event is emitted.
147147

148-
### writeStream.cursorTo(x, y[, callback])
148+
### writeStream.cursorTo(x[, y][, callback])
149149
<!-- YAML
150150
added: v0.7.7
151151
changes:

lib/readline.js

+5
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,11 @@ function cursorTo(stream, x, y, callback) {
11931193
if (callback !== undefined && typeof callback !== 'function')
11941194
throw new ERR_INVALID_CALLBACK(callback);
11951195

1196+
if (typeof y === 'function') {
1197+
callback = y;
1198+
y = undefined;
1199+
}
1200+
11961201
if (stream == null || (typeof x !== 'number' && typeof y !== 'number')) {
11971202
if (typeof callback === 'function')
11981203
process.nextTick(callback);

test/parallel/test-readline-csi.js

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ writable.data = '';
133133
assert.strictEqual(readline.cursorTo(writable, 1, 'a'), true);
134134
assert.strictEqual(writable.data, '\x1b[2G');
135135

136+
writable.data = '';
137+
assert.strictEqual(readline.cursorTo(writable, 1), true);
138+
assert.strictEqual(writable.data, '\x1b[2G');
139+
136140
writable.data = '';
137141
assert.strictEqual(readline.cursorTo(writable, 1, 2), true);
138142
assert.strictEqual(writable.data, '\x1b[3;2H');
@@ -141,6 +145,10 @@ writable.data = '';
141145
assert.strictEqual(readline.cursorTo(writable, 1, 2, common.mustCall()), true);
142146
assert.strictEqual(writable.data, '\x1b[3;2H');
143147

148+
writable.data = '';
149+
assert.strictEqual(readline.cursorTo(writable, 1, common.mustCall()), true);
150+
assert.strictEqual(writable.data, '\x1b[2G');
151+
144152
// Verify that cursorTo() throws on invalid callback.
145153
assert.throws(() => {
146154
readline.cursorTo(writable, 1, 1, null);

0 commit comments

Comments
 (0)