writeStream.getWindowSize()方法是tty模塊中類WriteStream的內置應用程序編程接口,用於獲取與此WriteStream對象相對應的TTY的大小。
用法:
writeStream.getWindowSize()
參數:此方法不接受任何參數。
返回值:此方法返回[numColumns,numRows]類型的數組,其中包含numColumns和numRows。
範例1: 文件名:index.js
// Node.js program to demonstrate the
// writeStream..getWindowSize() API
// 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;
// Getting window size of this write stream
// object by using .getWindowSize() API
const col = WriteStream.getWindowSize();
// Displaying the result
process.stdout.write(msg + col[0]);
// Exiting process
process.exit();
})// Binding server with port
.bind(1234, () => {
});
// Client sending message to server
client.send("number columns of writestream:- ", 0,
50, 1234, "localhost");
輸出:
number columns of writestream:- 182
範例2: 文件名:index.js
// Node.js program to demonstrate the
// writeStream..getWindowSize() API
// Creating and initializing a WriteStream object
let WriteStream = process.stdout;
// Getting window size of this write stream
// object by using .getWindowSize() method
const col = WriteStream.getWindowSize();
// Displaying the result
console.log("number rows of writestream:- " + col[1]);
使用以下命令運行index.js文件:
node index.js
輸出:
number rows of writestream:- 14
參考: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_getwindowsize
相關用法
- 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.getWindowSize() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。