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:
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.
npm install iterm2-size
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}`);
This library is difficult to test on GitHub actions, since GHA doesn't run iTerm2. CI just checks that eslint and typescript are happy.