From 2621840af5a7981f601a64d6355b6ea968a29c68 Mon Sep 17 00:00:00 2001 From: Umang Raghuvanshi Date: Mon, 17 Sep 2018 14:14:42 +0530 Subject: [PATCH 1/3] TTY: Document WriteStream.cursorTo and others Adds documentation for the following WriteStream instance methods: - cursorTo - moveCursor - clearLine - clearScreenDown - getWindowSize Fixes #9853. --- doc/api/tty.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/doc/api/tty.md b/doc/api/tty.md index cc95bfa9ae86ba..c6e5062ce073ea 100644 --- a/doc/api/tty.md +++ b/doc/api/tty.md @@ -106,6 +106,60 @@ 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) + + +* `x` {number} +* `y` {number} + +`writeStream.cursorTo` moves this `WriteStream`'s cursor to the specified +position. + +### writeStream.moveCursor(dx, dy) + + +* `dx` {number} +* `dy` {number} + +`writeStream.moveCursor` moves this `WriteStream`'s cursor *relative* to its +current position. + +### writeStream.clearLine(dir) + + +* `dir` {number} + * `-1` - to the left from cursor + * `1` - to the right from cursor + * `0` - the entire line + +`writeStream.clearLine` clears the current line of this `WriteStream` in a +direction identified by `dir`. + +### writeStream.clearScreenDown() + + +`writeStream.clearScreenDown` clears this `WriteStream` from the current +cursor down. + +### writeStream.getWindowSize() + +* Returns: {array} + +`writeStream.getWindowSize` returns the size of the [TTY]() corresponding +to this `WriteStream`. The array is of the type `[numColumns, numRows]` +where `numColumns` and `numRows` represents the number of columns and rows +in the corresponding [TTY](). + ### writeStream.isTTY - -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) - - -* `x` {number} -* `y` {number} - -`writeStream.cursorTo` moves this `WriteStream`'s cursor to the specified -position. - -### writeStream.moveCursor(dx, dy) - - -* `dx` {number} -* `dy` {number} - -`writeStream.moveCursor` moves this `WriteStream`'s cursor *relative* to its -current position. - ### writeStream.clearLine(dir) -`writeStream.clearScreenDown` clears this `WriteStream` from the current +`writeStream.clearScreenDown()` clears this `WriteStream` from the current cursor down. -### writeStream.getWindowSize() +### writeStream.columns -* Returns: {array} -`writeStream.getWindowSize` returns the size of the [TTY]() corresponding -to this `WriteStream`. The array is of the type `[numColumns, numRows]` -where `numColumns` and `numRows` represents the number of columns and rows -in the corresponding [TTY](). - -### writeStream.isTTY - - -A `boolean` that is always `true`. +A `number` specifying the number of columns the TTY currently has. This property +is updated whenever the `'resize'` event is emitted. -### writeStream.rows +### writeStream.cursorTo(x, y) -A `number` specifying the number of rows the TTY currently has. This property -is updated whenever the `'resize'` event is emitted. +* `x` {number} +* `y` {number} + +`writeStream.cursorTo()` moves this `WriteStream`'s cursor to the specified +position. ### writeStream.getColorDepth([env]) +* Returns: {number[]} + +`writeStream.getWindowSize()` returns the size of the [TTY](tty.html) corresponding +to this `WriteStream`. The array is of the type `[numColumns, numRows]` +where `numColumns` and `numRows` represent the number of columns and rows +in the corresponding [TTY](tty.html). + ## tty.isatty(fd) + +A `boolean` that is always `true`. + +### writeStream.moveCursor(dx, dy) + + +* `dx` {number} +* `dy` {number} + +`writeStream.moveCursor()` moves this `WriteStream`'s cursor *relative* to its +current position. + +### writeStream.rows + + +A `number` specifying the number of rows the TTY currently has. This property +is updated whenever the `'resize'` event is emitted. + [`net.Socket`]: net.html#net_class_net_socket [`process.stdin`]: process.html#process_process_stdin [`process.stdout`]: process.html#process_process_stdout From c8ac64d60ffe3dc3dadb84399a0c1a045f299b90 Mon Sep 17 00:00:00 2001 From: Umang Raghuvanshi Date: Fri, 5 Oct 2018 05:56:17 +0000 Subject: [PATCH 3/3] Reorder sections, fix line overflowing and header levels --- doc/api/tty.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/api/tty.md b/doc/api/tty.md index 1674d99520a6d5..87075b33ed70d0 100644 --- a/doc/api/tty.md +++ b/doc/api/tty.md @@ -164,18 +164,7 @@ to pass in an object with different settings. Use the `NODE_DISABLE_COLORS` environment variable to enforce this function to always return 1. -## writeStream.getWindowSize() - -* Returns: {number[]} - -`writeStream.getWindowSize()` returns the size of the [TTY](tty.html) corresponding -to this `WriteStream`. The array is of the type `[numColumns, numRows]` -where `numColumns` and `numRows` represent the number of columns and rows -in the corresponding [TTY](tty.html). - -## tty.isatty(fd) +### tty.isatty(fd) @@ -186,6 +175,17 @@ The `tty.isatty()` method returns `true` if the given `fd` is associated with a TTY and `false` if it is not, including whenever `fd` is not a non-negative integer. +### writeStream.getWindowSize() + +* Returns: {number[]} + +`writeStream.getWindowSize()` returns the size of the [TTY](tty.html) +corresponding to this `WriteStream`. The array is of the type +`[numColumns, numRows]` where `numColumns` and `numRows` represent the number +of columns and rows in the corresponding [TTY](tty.html). + ### writeStream.isTTY