cli-width
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Cli-width is a handy tool that helps developers obtain the stdout window width in JavaScript. It uses four fallback mechanisms - tty
, output.columns
, a custom environment variable and a default, to ensure it provides a width even if certain features are unavailable. This makes it highly reliable for defining layout dimensions in terminal-based applications.
In order to integrate Cli-width, first, install the package to your project using npm with the following command:
npm install --save cli-width
After installation, use it in your JavaScript file by requiring the library and calling the function:
const cliWidth = require('cli-width');
cliWidth(); // Returns the current width. For example, it might return 204.
Beyond basic reading of window width, Cli-width offers configurable options. For instance, you can set a default width value and a stream output to try to read from:
const cliWidth = require('cli-width');
const ttys = require('ttys');
cliWidth({
defaultWidth: 80,
output: ttys.output,
});
To configure a different tty module from which to read width, perform the following:
const cliWidth = require('cli-width');
const ttys = require('ttys');
cliWidth({
tty: ttys,
});
Cli-width also allows for environment value settings using the CLI_WIDTH
variable.
The official documentation of Cli-width, including the APIs and usage details, is on the GitHub repository page - git+ssh://git@github.com/knownasilya/cli-width.git. The GitHub README contains several practical examples to ease integration and usage of Cli-width in a variety of scenarios.