Package Exports
- iterm2-size
- iterm2-size/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (iterm2-size) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
iterm2-size
Get the size of the current iTerm2 window, in pixels. This might be useful for resizing images to fit, for example.
This library works ONLY if:
- You are on MacOS.
- You are using a relatively-modern version of iTerm2 that supports the Report Cell Size escape code.
- iTerm2 is the controlling terminal for your process.
This will work even if stdin or stdout is redirected to/from a file or piped to/from another process, which is why it was worth pulling this function out into a separate library.
Installation
npm install iterm2-size
API
Full API documentation is available.
Example:
import {getTerminalSize} from 'iterm2-size';
// Pass in rows/columns adjustments, if desired, to account for prompt height.
const {width, height} = await getTerminalSize({rows: -2});
console.error(`${width}x${height}`);
Testing
This library is difficult to test on GitHub actions, since GHA doesn't run iTerm2. CI just checks that eslint and typescript are happy.