Node.js writeStream.moveCursor() Method
Last Updated :
06 Apr, 2023
The writeStream.moveCursor() method is an inbuilt application programming interface of class WriteStream within tty module which is used to move the cursor of the write stream object relative to its current position.
Syntax:
const writeStream.moveCursor(dx, dy[, callback])
Parameters: This method takes the following parameters:
- dx: The x-axis coordinates with respect to the current coordinate.
- dy: The y-axis coordinate with respect to the current coordinate.
- callback: The callback function which executes after the operation.
Return Value: This method returns the Boolean value true if the cursor of the write stream object is moved relative to its current position.
Example 1: Filename: index.js
Javascript
const dgram = require( 'dgram' );
const client = dgram.createSocket( "udp4" );
const server = dgram.createSocket( "udp4" );
server.on( "message" , function (msg) {
let WriteStream = process.stdout;
const col = WriteStream.moveCursor(10, 7, () => {
});
process.stdout.write(msg + col);
process.exit();
})
.bind(1234, () => {
});
client.send( "cursor is moved :- " ,
0, 26, 1234, "localhost" );
|
Output:
cursor is moved :- true
Example 2: Filename: index.js
Javascript
let WriteStream = process.stdout;
const col = WriteStream.moveCursor(10, 7, () => {
});
console.log( "cursor is moved :- " + col);
|
Run the index.js file using the following command:
node index.js
Output:
cursor is moved :- true
Reference: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_movecursor_dx_dy_callback
Share your thoughts in the comments
Please Login to comment...