Skip to content

Commit

Permalink
Add cursorTo & clearLine to streams
Browse files Browse the repository at this point in the history
Summary:
Using `process.stdout.cursorTo` and `process.stdout.clearLine` will error in Flow because those definitions are missing.

```bash
Error: src/db/seeds/utils/helpers.js:9
  9:   process.stdout.cursorTo(0)
                      ^^^^^^^^ property `cursorTo`. Property not found in
  9:   process.stdout.cursorTo(0)
       ^^^^^^^^^^^^^^ stream$Writable

Error: src/db/seeds/utils/helpers.js:9
  9:   process.stdout.cursorTo(0)
                      ^^^^^^^^ property `cursorTo`. Property not found in
  9:   process.stdout.cursorTo(0)
       ^^^^^^^^^^^^^^ tty$WriteStream
```
[node/lib/readline.js](https://github.com/nodejs/node/blob/4a276cc2a960b3f9a138ac3a99c9249a63b4d472/lib/readline.js#L1061-L1080)
[node/lib/tty.js](https://github.com/nodejs/node/blob/8bf48bf2cf714125fef91fd0651d3517b8953034/lib/tty.js#L131-L134)

```bash
Error: src/db/seeds/utils/helpers.js:10
 10:   process.stdout.clearLine()
                      ^^^^^^^^^ property `clearLine`. Property not found in
 10:   process.stdout.clearLine()
       ^^^^^^^^^^^^^^ stream$Writable

Error: src/db/seeds/utils/helpers.js:10
 10:   process.stdout.clearLine()
                      ^^^^^^^^^ property `clearLine`. Property not found in
 10:   process.stdout.clearLine()
       ^^^^^^^^^^^^^^ tty$WriteStream
```
[node/lib/readline.js](https://github.com/nodejs/node/blob/4a276cc2a960b3f9a138ac3a99c9249a63b4d472/lib/readline.js#L1103-L1124)
[node/lib/tty.js](https://github.com/nodejs/node/blob/8bf48bf2cf714125fef91fd0651d3517b8953034/lib/tty.js#L139-L142)

I'm not sure if I added them in the correct place, so please check and let me know.

Pull Request resolved: #7082

Reviewed By: panagosg7

Differential Revision: D26883834

Pulled By: mroch

fbshipit-source-id: fb9ecffa8dafb250538a091a57ab454706effe24
  • Loading branch information
reyronald authored and facebook-github-bot committed Mar 8, 2021
1 parent 37ed265 commit 4b30713
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 46 deletions.
17 changes: 16 additions & 1 deletion lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2067,9 +2067,24 @@ declare class tty$ReadStream extends net$Socket {
}
declare class tty$WriteStream extends net$Socket {
constructor(fd: number) : void;
/**
* Clears the current line of this `WriteStream` in a direction identified by `dir`.
*
* TODO: takes a callback and returns `boolean` in v12+
*/
clearLine(dir: -1 | 0 | 1): void;
columns : number;
/**
* Moves this WriteStream's cursor to the specified position
*
* TODO: takes a callback and returns `boolean` in v12+
*/
cursorTo(
x: number,
y?: number
): void;
isTTY : true;
rows : number;
isTTY : true
}

declare module "tty" {
Expand Down
90 changes: 45 additions & 45 deletions tests/node_tests/node_tests.exp
Original file line number Diff line number Diff line change
Expand Up @@ -1636,26 +1636,26 @@ References:
process/emitWarning.js:10:1
10| process.emitWarning(); // error
^^^^^^^^^^^^^^^^^^^^^ [1]
<BUILTINS>/node.js:2655:24
2655| emitWarning(warning: string | Error): void;
<BUILTINS>/node.js:2670:24
2670| emitWarning(warning: string | Error): void;
^^^^^^ [2]
<BUILTINS>/node.js:2655:33
2655| emitWarning(warning: string | Error): void;
<BUILTINS>/node.js:2670:33
2670| emitWarning(warning: string | Error): void;
^^^^^ [3]
<BUILTINS>/node.js:2656:3
2656| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void;
<BUILTINS>/node.js:2671:3
2671| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [4]
<BUILTINS>/node.js:2657:3
2657| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
<BUILTINS>/node.js:2672:3
2672| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [5]
<BUILTINS>/node.js:2658:3
<BUILTINS>/node.js:2673:3
v-----------
2658| emitWarning(
2659| warning: string,
2660| type: string,
2661| code: string,
2662| ctor?: (...empty) => mixed
2663| ): void;
2673| emitWarning(
2674| warning: string,
2675| type: string,
2676| code: string,
2677| ctor?: (...empty) => mixed
2678| ): void;
------^ [6]


Expand All @@ -1674,14 +1674,14 @@ References:
process/emitWarning.js:11:21
11| process.emitWarning(42); // error
^^ [1]
<BUILTINS>/node.js:2656:24
2656| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void;
<BUILTINS>/node.js:2671:24
2671| emitWarning(warning: string, typeOrCtor: string | (...empty) => mixed): void;
^^^^^^ [2]
<BUILTINS>/node.js:2657:24
2657| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
<BUILTINS>/node.js:2672:24
2672| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
^^^^^^ [3]
<BUILTINS>/node.js:2659:14
2659| warning: string,
<BUILTINS>/node.js:2674:14
2674| warning: string,
^^^^^^ [4]


Expand All @@ -1699,11 +1699,11 @@ References:
process/emitWarning.js:12:29
12| process.emitWarning("blah", 42); // error
^^ [1]
<BUILTINS>/node.js:2657:38
2657| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
<BUILTINS>/node.js:2672:38
2672| emitWarning(warning: string, type: string, codeOrCtor: string | (...empty) => mixed): void;
^^^^^^ [2]
<BUILTINS>/node.js:2660:11
2660| type: string,
<BUILTINS>/node.js:2675:11
2675| type: string,
^^^^^^ [3]


Expand All @@ -1719,8 +1719,8 @@ References:
process/emitWarning.js:13:37
13| process.emitWarning("blah", "blah", 42); // error
^^ [1]
<BUILTINS>/node.js:2661:11
2661| code: string,
<BUILTINS>/node.js:2676:11
2676| code: string,
^^^^^^ [2]


Expand All @@ -1734,8 +1734,8 @@ Cannot cast `process.emitWarning(...)` to string because undefined [1] is incomp
^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/node.js:2655:41
2655| emitWarning(warning: string | Error): void;
<BUILTINS>/node.js:2670:41
2670| emitWarning(warning: string | Error): void;
^^^^ [1]
process/emitWarning.js:14:31
14| (process.emitWarning("blah"): string); // error
Expand Down Expand Up @@ -1800,8 +1800,8 @@ References:
process/nextTick.js:27:3
27| (a: string, b: number, c: boolean) => {} // Error: too few arguments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]
<BUILTINS>/node.js:2684:21
2684| nextTick: <T>(cb: (...T) => mixed, ...T) => void;
<BUILTINS>/node.js:2699:21
2699| nextTick: <T>(cb: (...T) => mixed, ...T) => void;
^^^^^^^^^^^^^^^ [2]


Expand All @@ -1815,8 +1815,8 @@ Cannot cast `process.allowedNodeEnvironmentFlags` to string because `Set` [1] is
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/node.js:2644:32
2644| allowedNodeEnvironmentFlags: Set<string>;
<BUILTINS>/node.js:2659:32
2659| allowedNodeEnvironmentFlags: Set<string>;
^^^^^^^^^^^ [1]
process/process.js:5:39
5| (process.allowedNodeEnvironmentFlags: string); // error
Expand Down Expand Up @@ -2007,8 +2007,8 @@ Cannot cast `url.parse(...).query` to empty because string [1] is incompatible w
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/node.js:2223:12
2223| query: string | null
<BUILTINS>/node.js:2238:12
2238| query: string | null
^^^^^^ [1]
url/url.js:4:50
4| (url.parse('http://example.com/?foo=bar').query: empty); // error, string | null
Expand All @@ -2024,8 +2024,8 @@ Cannot cast `url.parse(...).query` to empty because null [1] is incompatible wit
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/node.js:2223:21
2223| query: string | null
<BUILTINS>/node.js:2238:21
2238| query: string | null
^^^^ [1]
url/url.js:4:50
4| (url.parse('http://example.com/?foo=bar').query: empty); // error, string | null
Expand All @@ -2041,8 +2041,8 @@ Cannot cast `url.parse(...).query` to empty because object type [1] is incompati
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/node.js:2228:12
2228| query: { [string]: string, ... }
<BUILTINS>/node.js:2243:12
2243| query: { [string]: string, ... }
^^^^^^^^^^^^^^^^^^^^^^^^^ [1]
url/url.js:5:56
5| (url.parse('http://example.com/?foo=bar', true).query: empty); // error, object
Expand All @@ -2058,8 +2058,8 @@ Cannot cast `url.parse(...).query` to empty because string [1] is incompatible w
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/node.js:2215:12
2215| query: string | null | { [string]: string, ... },
<BUILTINS>/node.js:2230:12
2230| query: string | null | { [string]: string, ... },
^^^^^^ [1]
url/url.js:8:70
8| (url.parse('http://example.com/?foo=bar', parseQueryString).query: empty); // error, string | null | object
Expand All @@ -2075,8 +2075,8 @@ Cannot cast `url.parse(...).query` to empty because null [1] is incompatible wit
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/node.js:2215:21
2215| query: string | null | { [string]: string, ... },
<BUILTINS>/node.js:2230:21
2230| query: string | null | { [string]: string, ... },
^^^^ [1]
url/url.js:8:70
8| (url.parse('http://example.com/?foo=bar', parseQueryString).query: empty); // error, string | null | object
Expand All @@ -2092,8 +2092,8 @@ Cannot cast `url.parse(...).query` to empty because object type [1] is incompati
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/node.js:2215:28
2215| query: string | null | { [string]: string, ... },
<BUILTINS>/node.js:2230:28
2230| query: string | null | { [string]: string, ... },
^^^^^^^^^^^^^^^^^^^^^^^^^ [1]
url/url.js:8:70
8| (url.parse('http://example.com/?foo=bar', parseQueryString).query: empty); // error, string | null | object
Expand Down

0 comments on commit 4b30713

Please sign in to comment.