Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
The term-size npm package is a simple utility that allows you to get the size (width and height) of the terminal window in which your Node.js application is running. It's particularly useful for CLI applications that need to adjust their output based on the available terminal space.
Get Terminal Size
This feature allows you to retrieve the current size of the terminal (width as columns and height as rows). The code sample demonstrates how to use term-size to get the terminal dimensions and then print them to the console.
const termSize = require('term-size');
const {columns, rows} = termSize();
console.log(`Columns: ${columns}, Rows: ${rows}`);
Similar to term-size, window-size is a package that can be used to get the size of the terminal window. However, window-size offers additional methods for getting size information based on different criteria (e.g., environment variables, tty dimensions), which might make it more versatile in certain scenarios.
cli-width is another package that provides functionality to get the width of the terminal. Unlike term-size, which provides both width and height, cli-width focuses solely on the width aspect. This makes it a simpler choice if width is the only dimension you care about.
Reliably get the terminal window size
Because process.stdout.columns
doesn't exist when run non-interactively, for example, in a child process or when piped. This module even works when all the TTY file descriptors are redirected!
Confirmed working on macOS, Linux, and Windows.
$ npm install --save term-size
const termSize = require('term-size');
termSize();
//=> {columns: 143, rows: 24}
Returns an Object
with columns
and rows
properties.
MIT © Sindre Sorhus
FAQs
Reliably get the terminal window size (columns & rows)
The npm package term-size receives a total of 3,092,794 weekly downloads. As such, term-size popularity was classified as popular.
We found that term-size demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.