0.0.1 • Published 4 months ago
iterm2-size v0.0.1
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.
0.0.1
4 months ago