writeStream.moveCursor()方法是tty模塊中WriteStream類的內置應用程序編程接口,用於將寫入流對象的光標相對於其當前位置移動。
用法:
const writeStream.moveCursor(dx, dy[, callback])
參數:此方法采用以下參數:
- dx:相對於當前坐標的x軸坐標。
- dy:y軸坐標相對於當前坐標。
- callback:該回調函數將在操作後執行。
返回值:如果寫入流對象的光標相對於其當前位置移動,則此方法返回布爾值true。
範例1: 文件名: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");
輸出:
curser is moved:- true
範例2: 文件名: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);
使用以下命令運行index.js文件:
node index.js
輸出:
curser is moved:- true
參考:https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_movecursor_dx_dy_callback
相關用法
- Node.js console.timeLog()用法及代碼示例
- Node.js GM charcoal()用法及代碼示例
- Node.js GM blur()用法及代碼示例
- Node.js GM sharpen()用法及代碼示例
- Node.js GM drawLine()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Node.js writeStream.moveCursor() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。