1.1.1 • Published 6 years ago

window-size v1.1.1

Weekly downloads
5,021,220
License
MIT
Repository
github
Last release
6 years ago

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

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

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.

@microsoft/bf-qnamakerbalena-clireact-native-bluetooth2cn-luis-apis@arisageha/react-lazyload@arisageha/react-lazyload-fixcthpb-plugin-socialvue-fonts@infinitebrahmanuniverse/nolb-wind@everything-registry/sub-chunk-3149ka-flow.jskafirchain-tetrisleveldb-editleveldb-editorhendo-clihendo-cli-luozheaohobohelp-widgetgucci-ganglanguage-codeslerna-build-managerjaskjask-clijec-jask-clijira-precommit-hooklodash-modularizenode-fzfluis-apisluis-apis-mooncakeluisnquinmi-iscrollmsgboxhello_world_founderjs-utils-jll2inquirer-helpersicons-vue-testimage-asciify-clinative-kakao-loginnative-google-loginnative-apple-loginwhoarewemiguelcostero-ng2-toastymemento-morilrbceshinodeshotngi-syncmathquillcustommathquillcustomlibmegalog@the91end/react-auth@unibtc/release-it@resdir/console@snap-doc/cli@rstacruz/pnpm@sudophunk/fulido@xotic750/eslint-find-rules@zambezi/ez-buildalgorithmic-vomit@willebergh/gorilla@voila/commonagora-cli@yplabs-ltd/react-native-detectorangular-project-generatoraxios-yet-another-proxy-fixawesome-react-stars@artiso-solutions/vue-html-to-paperapi-lessbirkeland_bosbirken-react-native-community-image-editor@akameco/eslint-find-rules@codedungeon/code-assistant@codedungeon/messengercli-stylesconfig-builder@deboxsoft/release-it@bitfirer/vue-qriouslybrainlife@beauraines/rtm-cli@boundless-inc/mobiledoc-dom-rendererbufferizedburger-image-editorcanvas-fingerprint@bonsaiswap-lib/lib@bonsaiswapv3/core@bonsaiswapv3/deploy@borealisswap/borealis-swap-lib@caneco/siemacarousel-react@ccheever/inquirer@cdevine49/react-numeric-input3.0.0endictelad-shaked-countrieselad-shaked-countrydynamic-terminaleasyplayer-myeslint-find-ruleseslint-formatter-bottleneckembark-coreembark
1.1.1

6 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.3.0

7 years ago

0.2.0

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

10 years ago