{"id":15640159,"url":"https://github.com/jonschlinkert/window-size","last_synced_at":"2025-04-12T22:28:13.361Z","repository":{"id":14150254,"uuid":"16855987","full_name":"jonschlinkert/window-size","owner":"jonschlinkert","description":"Reliable way to to get the height and width of the terminal/console in a node.js environment.","archived":false,"fork":false,"pushed_at":"2024-08-12T13:33:11.000Z","size":1152,"stargazers_count":81,"open_issues_count":2,"forks_count":15,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-29T13:01:30.167Z","etag":null,"topics":["cli","command-line","console","height","iterm","optimist","size","term","term-size","terminal","width","window","yargs"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"jonschlinkert"}},"created_at":"2014-02-15T03:42:28.000Z","updated_at":"2024-10-19T06:49:42.000Z","dependencies_parsed_at":"2024-11-18T07:13:52.922Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/window-size","commit_stats":{"total_commits":42,"total_committers":8,"mean_commits":5.25,"dds":0.5952380952380952,"last_synced_commit":"28f3e0ffba18846d5db4919a65804aa076e4ffc5"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fwindow-size","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fwindow-size/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fwindow-size/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fwindow-size/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/window-size/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248639191,"owners_count":21137798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","command-line","console","height","iterm","optimist","size","term","term-size","terminal","width","window","yargs"],"created_at":"2024-10-03T11:31:46.546Z","updated_at":"2025-04-12T22:28:13.311Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","funding_links":["https://github.com/sponsors/jonschlinkert"],"categories":[],"sub_categories":[],"readme":"# window-size [![NPM version](https://img.shields.io/npm/v/window-size.svg?style=flat)](https://www.npmjs.com/package/window-size) [![NPM monthly downloads](https://img.shields.io/npm/dm/window-size.svg?style=flat)](https://npmjs.org/package/window-size)  [![NPM total downloads](https://img.shields.io/npm/dt/window-size.svg?style=flat)](https://npmjs.org/package/window-size) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/window-size.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/window-size) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/window-size.svg?style=flat\u0026label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/window-size)\n\n\u003e 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.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save window-size\n```\n\n## Usage\n\n```js\nvar size = require('window-size');\n```\n\n## CLI\n\n```sh\n$ window-size\n# height: 40\n# width : 145\n```\n\n## API\n\n### windowSize\n\nThe main export is either an object with `width` and `height` properties, or `undefined` if unable to get width and height.\n\n```js\nvar size = require('window-size');\nconsole.log(size); \n//=\u003e {width: 80, height: 25}\n```\n\n### .get\n\nCalls the main function to get the up-to-date window size.\n\n```js\nconsole.log(size.get());\n//=\u003e {width: 80, height: 25}\n```\n\n**Example**\n\nSee [example.js](example.js) for the code used in the below gif.\n\n```js\nprocess.stdout.on('resize', function() {\n  console.log(size.get());\n});\n```\n\n![resize event example](https://github.com/jonschlinkert/window-size/blob/master/resize.gif)\n\n**HEADS UP!**\n\nNote that some platforms only provide the initial terminal size, not the actual size after it has been resized by the user.\n\n### .env\n\nGet `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`.\n\n```js\nconsole.log(size.env());\n```\n\n### .tty\n\nAttempts 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`.\n\n```js\nconsole.log(size.tty());\n```\n\n### .win\n\nGet the terminal size in Windows 10+.\n\n```js\nconsole.log(size.win());\n```\n\nNote that this method calls [execSync](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options) to get the size, and must be called directly, as it **is not** called by the main function.\n\n### .tput\n\nGet the terminal size by calling the unix `$ tput` command.\n\n```js\nconsole.log(size.tput());\n```\n\nNote that this method calls [execSync](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options) to get the size, and must be called directly, as it **is not** called by the main function.\n\n### utils\n\nIn 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.\n\nBecause of this, the functions have been exported in a separate file and can be required directly.\n\n```js\nvar utils = require('window-size/utils');\nconsole.log(utils.win());\n```\n\n## About\n\n### Related projects\n\n* [base-cli](https://www.npmjs.com/package/base-cli): Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a… [more](https://github.com/node-base/base-cli) | [homepage](https://github.com/node-base/base-cli \"Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a few plugins, like 'base-store', 'base-options' and 'base-data'.\")\n* [lint-deps](https://www.npmjs.com/package/lint-deps): CLI tool that tells you when dependencies are missing from package.json and offers you a… [more](https://github.com/jonschlinkert/lint-deps) | [homepage](https://github.com/jonschlinkert/lint-deps \"CLI tool that tells you when dependencies are missing from package.json and offers you a choice to install them. Also tells you when dependencies are listed in package.json but are not being used anywhere in your project. Node.js command line tool and API\")\n* [yargs](https://www.npmjs.com/package/yargs): yargs the modern, pirate-themed, successor to optimist. | [homepage](http://yargs.js.org/ \"yargs the modern, pirate-themed, successor to optimist.\")\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 23 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 11 | [doowb](https://github.com/doowb) |  \n| 4  | [bcoe](https://github.com/bcoe) |  \n| 3  | [icyflame](https://github.com/icyflame) |  \n| 2  | [derhuerst](https://github.com/derhuerst) |  \n| 1  | [karliky](https://github.com/karliky) |  \n\n### Building docs\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n### Running tests\n\nRunning 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:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n### Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.7.0, on July 27, 2018._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fwindow-size","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fwindow-size","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fwindow-size/lists"}