Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e474c67

Browse filesBrowse 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 <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>
1 parent e51f924 commit e474c67
Copy full SHA for e474c67

File tree

Expand file treeCollapse file tree

4 files changed

+15
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+15
-2
lines changed
Open diff view settings
Collapse file

‎doc/api/readline.md‎

Copy file name to clipboardExpand all lines: doc/api/readline.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
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:
Collapse file

‎doc/api/tty.md‎

Copy file name to clipboardExpand all lines: doc/api/tty.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
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:
Collapse file

‎lib/readline.js‎

Copy file name to clipboardExpand all lines: lib/readline.js
+5Lines changed: 5 additions & 0 deletions
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);
Collapse file

‎test/parallel/test-readline-csi.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-readline-csi.js
+8Lines changed: 8 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.