iterm2-size - v1.0.0
    Preparing search index...

    iterm2-size - v1.0.0

    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.

    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.