Skip to content
Related Articles

Related Articles

Improve Article

Node.js writeStream.moveCursor() Method

  • Last Updated : 06 Sep, 2020

The writeStream.moveCursor() method is an inbuilt application programming interface of class WriteStream within tty module which is used to move the cursor of 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 coordinate with respect to current coordinate.
  • dy: The y axis coordinate with respect to current coordinate.
  • callback: The callback function after which executes after the operation.

Return Value: This method returns Boolean value true if the cursor of write stream object is moved relative to its current position.

Example 1: Filename: index.js






// Node.js program to demonstrate the
// writeStream.moveCursor() method
  
// Importing dgram module
var dgram = require('dgram');
  
// Creating and initializing client 
// and server socket
var client = dgram.createSocket("udp4");
var server = dgram.createSocket("udp4");
  
// Handling the message event
server.on("message", function (msg) {
  
  // Creating and initializing a
  // WriteStream object
  let WriteStream = process.stdout;
  
  // Moving cursor to with respect
  // to previous position by using
  // moveCursor() method
  const col = WriteStream.moveCursor(10, 7, ()=>{
  });
  
  // Displaying the result
  process.stdout.write(msg + col);
  
  // Exiting process
  process.exit();
})
// Binding server with port
.bind(1234, () => {
});
  
// Client sending message to server
client.send("curser is moved :-  "
        0, 26, 1234, "localhost");

Output:


          curser is moved :-  true

Example 2: Filename: index.js




// Node.js program to demonstrate the
// writeStream.moveCursor() method
  
// Creating and initializing a
// WriteStream object
let WriteStream = process.stdout;
  
// Moving cursor to with respect to
// previous position by using 
// moveCursor() method
const col = WriteStream.moveCursor(10, 7, ()=>{
});
  
// Displaying the result
console.log("curser is moved :-  " + col);

Run the index.js file using the following command:

node index.js

Output:


          curser is moved :-  true

Reference:  https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_movecursor_dx_dy_callback




My Personal Notes arrow_drop_up
Recommended Articles
Page :