If my program is being piped to another program at the command-line, is there any way for me to still determine the width thereof?
I'm working in Node, if that's relevant, although any general POSIX solution is welcome (I can figure out how to port it to my environment myself.) Currently, I can use process.stdout.columns
in Node; but that's linked to the process.stdout
, which in this case is piped.
Actually, POSIX does not define the C ioctl
call used for getting the window size (see standard). But the TIOCGWINSZ
call (or similar TIOCGSIZE
) is widely available. Node probably relies on that in its checks.
This package checks the width for the standard output and failing that, checks the standard error: window-size (see source code).
A similar question was asked before in How wide is the node.js console?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With