writeStream.clearLine()是tty模塊中WriteStream類的內置應用程序編程接口,用於清除此寫入流對象的當前行。
用法:
writeStream.clearLine(dir[, callback])
參數:此方法將以下參數作為參數:
- dir:整數值,定義線的選擇。
- callback:操作完成後調用。
返回值:如果寫入對象行是清除的,則此方法返回布爾值true,否則返回false。
範例1: 文件名:index.js
// Node.js program to demonstrate the
// writeStream.clearLine() 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;
// Clearing the line
// by using clearLine() API
const col = WriteStream.clearLine();
// 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("The line is clear:- ",
0, 26, 1234, "localhost");
輸出:
The line is clear:- true
範例2: 文件名:index.js
// Node.js program to demonstrate the
// writeStream.clearLine() method
// Creating and initializing a
// WriteStream object
let WriteStream = process.stdout;
// Clearing the line
// by using clearLine() API
const col = WriteStream.clearLine();
// Displaying the result
console.log("The line is clear:- " + col);
使用以下命令運行index.js文件:
node index.js
輸出:
The line is clear:- true
參考:https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_clearline_dir_callback
相關用法
- Node.js console.timeLog()用法及代碼示例
- Node.js GM channel()用法及代碼示例
- Node.js GM blur()用法及代碼示例
- Node.js GM chop()用法及代碼示例
- Node.js GM implode()用法及代碼示例
- Node.js GM edge()用法及代碼示例
- Node.js GM crop()用法及代碼示例
- Node.js GM charcoal()用法及代碼示例
- Node.js GM gaussian()用法及代碼示例
- Node.js GM enhance()用法及代碼示例
- Node.js GM flop()用法及代碼示例
- Node.js GM flip()用法及代碼示例
- Node.js GM despeckle()用法及代碼示例
- Node.js GM bordercolor()用法及代碼示例
- Node.js GM border()用法及代碼示例
- Node.js GM equalize()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Node.js writeStream.clearLine() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。