All Projects ā†’ jonschlinkert ā†’ Window Size

jonschlinkert / Window Size

Licence: mit
Reliable way to to get the height and width of the terminal/console in a node.js environment.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Window Size

Wonders
šŸŒˆ Declarative JavaScript framework to build command-line applications.
Stars: āœ­ 34 (-56.96%)
Mutual labels:  cli, terminal, command-line, console
Nnn
nĀ³ The unorthodox terminal file manager
Stars: āœ­ 13,138 (+16530.38%)
Mutual labels:  cli, terminal, command-line, console
Tooling
Advancing Node.js as a framework for writing great tools
Stars: āœ­ 98 (+24.05%)
Mutual labels:  cli, terminal, command-line, console
Mandown
man-page inspired Markdown viewer
Stars: āœ­ 173 (+118.99%)
Mutual labels:  cli, terminal, command-line, console
Ascii
šŸ‘¾ ASCII Roulette :: ascii art video chat on the cli
Stars: āœ­ 202 (+155.7%)
Mutual labels:  cli, terminal, command-line, console
Laravel Zero
A PHP framework for console artisans
Stars: āœ­ 2,821 (+3470.89%)
Mutual labels:  cli, terminal, command-line, console
Word Wrap
Wrap words to a specified length.
Stars: āœ­ 107 (+35.44%)
Mutual labels:  cli, terminal, command-line, console
Cointop
A fast and lightweight interactive terminal based UI application for tracking cryptocurrencies šŸš€
Stars: āœ­ 2,912 (+3586.08%)
Mutual labels:  cli, terminal, command-line, console
Crossline
A small, self-contained, zero-config, MIT licensed, cross-platform, readline and libedit replacement.
Stars: āœ­ 53 (-32.91%)
Mutual labels:  cli, terminal, command-line, console
Jquery.terminal
jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
Stars: āœ­ 2,623 (+3220.25%)
Mutual labels:  cli, terminal, command-line, console
Rang
A Minimal, Header only Modern c++ library for terminal goodies šŸ’„āœØ
Stars: āœ­ 1,080 (+1267.09%)
Mutual labels:  cli, terminal, command-line, console
Tui Consolelauncher
Linux CLI Launcher for Android
Stars: āœ­ 861 (+989.87%)
Mutual labels:  cli, terminal, console
Radian
A 21 century R console
Stars: āœ­ 878 (+1011.39%)
Mutual labels:  cli, terminal, console
Tldr
šŸ“š Collaborative cheatsheets for console commands
Stars: āœ­ 36,408 (+45986.08%)
Mutual labels:  terminal, command-line, console
Clifx
Declarative framework for building command line interfaces
Stars: āœ­ 900 (+1039.24%)
Mutual labels:  cli, terminal, command-line
Video To Ascii
It is a simple python package to play videos in the terminal using characters as pixels
Stars: āœ­ 960 (+1115.19%)
Mutual labels:  cli, terminal, console
Taskline
Tasks, boards & notes for the command-line habitat
Stars: āœ­ 78 (-1.27%)
Mutual labels:  cli, terminal, console
Termtools
Customize your terminal using JavaScript. With themes, extra alias and functions, we combine the power from both JavaScript and Bash.
Stars: āœ­ 42 (-46.84%)
Mutual labels:  cli, terminal, console
Ed
A modern UNIX ed (line editor) clone written in Go
Stars: āœ­ 44 (-44.3%)
Mutual labels:  cli, terminal, command-line
Imgp
šŸ“ø High-performance cli batch image resizer and rotator
Stars: āœ­ 744 (+841.77%)
Mutual labels:  terminal, command-line, console

window-size NPM version NPM monthly downloads NPM total downloads Linux Build Status Windows Build Status

Reliable way to get the height and width of terminal/console, since it's not calculated or updated the same way on all platforms, environments and node.js versions.

Install

Install with npm:

$ npm install --save window-size

Usage

var size = require('window-size');

CLI

$ window-size
# height: 40
# width : 145

API

windowSize

The main export is either an object with width and height properties, or undefined if unable to get width and height.

var size = require('window-size');
console.log(size); 
//=> {width: 80, height: 25}

.get

Calls the main function to get the up-to-date window size.

console.log(size.get());
//=> {width: 80, height: 25}

Example

See example.js for the code used in the below gif.

process.stdout.on('resize', function() {
  console.log(size.get());
});

resize event example

HEADS UP!

Note that some platforms only provide the initial terminal size, not the actual size after it has been resized by the user.

.env

Get process.env.COLUMNS and process.env.ROWS, if defined. Called by the main function if for some reason size was not available from process.stdout and process.stderr.

console.log(size.env());

.tty

Attempts to get the size from tty. Called by the main function if for some reason size was not available from process.stdout, process.stderr or process.env.

console.log(size.tty());

.win

Get the terminal size in Windows 10+.

console.log(size.win());

Note that this method calls execSync to get the size, and must be called directly, as it is not called by the main function.

.tput

Get the terminal size by calling the unix $ tput command.

console.log(size.tput());

Note that this method calls execSync to get the size, and must be called directly, as it is not called by the main function.

utils

In some environments the main export may not be able to find a window size using the default methods. In this case, size will be undefined and the functions will not be exported.

Because of this, the functions have been exported in a separate file and can be required directly.

var utils = require('window-size/utils');
console.log(utils.win());

About

Related projects

  • base-cli: Plugin for base-methods that maps built-in methods to CLI args (also supports methods from aā€¦ more | homepage
  • lint-deps: CLI tool that tells you when dependencies are missing from package.json and offers you aā€¦ more | homepage
  • yargs: yargs the modern, pirate-themed, successor to optimist. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

Commits Contributor
23 jonschlinkert
11 doowb
4 bcoe
3 icyflame
2 derhuerst
1 karliky

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright Ā© 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.7.0, on July 27, 2018.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].