writeStream.columns屬性是tty模塊中WriteStream類的內置應用程序編程接口,該接口用於獲取此write Stream對象具有的列數。
用法:
const writeStream.columns
返回值:此屬性返回此寫入Stream對象包含的列數。
範例1: 文件名:index.js
Javascript
// Node.js program to demonstrate the
// writeStream.columns property
// Importing dgram module
var dgram = require('dgram');
// Creating and initializing client
// and server socket
var client = dgram.createSocket("udp4");
var server = dgram.createSocket("udp4");
// Cathing the message event
server.on("message", function (msg) {
// Creating and initializing a
// WriteStream object
let WriteStream = process.stdout;
// Getting number of columns
// by using columns API
const col = WriteStream.columns;
// 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("Number of Columns:- ",
0, 21, 1234, "localhost");
輸出:
Number of Columns:- 182
範例2: 文件名:index.js
Javascript
// Node.js program to demonstrate the
// writeStream.columns property
// Creating and initializing a WriteStream object
let WriteStream = process.stdout;
// Getting number of columns
// by using columns API
const col = WriteStream.columns;
// Displaying the result
console.log("Number of Columns:- " + col);
輸出:
Number of Columns:- 182
使用以下命令運行index.js文件:
node index.js
參考: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_columns
相關用法
- Node.js GM charcoal()用法及代碼示例
- Node.js GM blur()用法及代碼示例
- Node.js GM sharpen()用法及代碼示例
- Node.js GM drawLine()用法及代碼示例
- Node.js GM drawArc()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawBezier()用法及代碼示例
- Node.js GM drawCircle()用法及代碼示例
- Node.js GM drawEllipse()用法及代碼示例
- Node.js GM drawPolygon()用法及代碼示例
- Node.js GM drawRectangle()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Node.js writeStream.columns Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。