Skip to content

Commit bf17708

Browse files
ur0targos
authored andcommitted
tty: document WriteStream.cursorTo() and others
Adds documentation for the following `WriteStream` instance methods: - `WriteStream.clearLine()` - `WriteStream.clearScreenDown()` - `WriteStream.cursorTo()` - `WriteStream.getWindowSize()` - `WriteStream.moveCursor()` PR-URL: #22893 Fixes: #9853 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]>
1 parent bd59d4e commit bf17708

File tree

1 file changed

+62
-8
lines changed

1 file changed

+62
-8
lines changed

doc/api/tty.md

+62-8
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,46 @@ process.stdout.on('resize', () => {
9999
});
100100
```
101101

102-
### writeStream.columns
102+
### writeStream.clearLine(dir)
103103
<!-- YAML
104104
added: v0.7.7
105105
-->
106106

107-
A `number` specifying the number of columns the TTY currently has. This property
108-
is updated whenever the `'resize'` event is emitted.
107+
* `dir` {number}
108+
* `-1` - to the left from cursor
109+
* `1` - to the right from cursor
110+
* `0` - the entire line
109111

110-
### writeStream.isTTY
112+
`writeStream.clearLine()` clears the current line of this `WriteStream` in a
113+
direction identified by `dir`.
114+
115+
### writeStream.clearScreenDown()
111116
<!-- YAML
112-
added: v0.5.8
117+
added: v0.7.7
113118
-->
114119

115-
A `boolean` that is always `true`.
120+
`writeStream.clearScreenDown()` clears this `WriteStream` from the current
121+
cursor down.
116122

117-
### writeStream.rows
123+
### writeStream.columns
118124
<!-- YAML
119125
added: v0.7.7
120126
-->
121127

122-
A `number` specifying the number of rows the TTY currently has. This property
128+
A `number` specifying the number of columns the TTY currently has. This property
123129
is updated whenever the `'resize'` event is emitted.
124130

131+
### writeStream.cursorTo(x, y)
132+
<!-- YAML
133+
added: v0.7.7
134+
-->
135+
136+
* `x` {number}
137+
* `y` {number}
138+
139+
`writeStream.cursorTo()` moves this `WriteStream`'s cursor to the specified
140+
position.
141+
125142
### writeStream.getColorDepth([env])
126143
<!-- YAML
127144
added: v9.9.0
@@ -148,6 +165,43 @@ to pass in an object with different settings.
148165
Use the `NODE_DISABLE_COLORS` environment variable to enforce this function to
149166
always return 1.
150167

168+
### writeStream.getWindowSize()
169+
<!-- YAML
170+
added: v0.7.7
171+
-->
172+
* Returns: {number[]}
173+
174+
`writeStream.getWindowSize()` returns the size of the [TTY](tty.html)
175+
corresponding to this `WriteStream`. The array is of the type
176+
`[numColumns, numRows]` where `numColumns` and `numRows` represent the number
177+
of columns and rows in the corresponding [TTY](tty.html).
178+
179+
### writeStream.isTTY
180+
<!-- YAML
181+
added: v0.5.8
182+
-->
183+
184+
A `boolean` that is always `true`.
185+
186+
### writeStream.moveCursor(dx, dy)
187+
<!-- YAML
188+
added: v0.7.7
189+
-->
190+
191+
* `dx` {number}
192+
* `dy` {number}
193+
194+
`writeStream.moveCursor()` moves this `WriteStream`'s cursor *relative* to its
195+
current position.
196+
197+
### writeStream.rows
198+
<!-- YAML
199+
added: v0.7.7
200+
-->
201+
202+
A `number` specifying the number of rows the TTY currently has. This property
203+
is updated whenever the `'resize'` event is emitted.
204+
151205
## tty.isatty(fd)
152206
<!-- YAML
153207
added: v0.5.8

0 commit comments

Comments
 (0)