How to determine the width of the terminal when transmitting over a channel (for example, to a pager?)

If my program is passed to another program on the command line, is there a way to determine its width?

I work in Node if it is relevant, although any general POSIX solution is welcome (I can figure out how to transfer it to my environment myself). I can currently use process.stdout.columnsin Node; but associated with process.stdout, which in this case is transmitted over the channels.

+4
source share
1 answer

In fact, POSIX does not define the C call ioctlused to get the window size (see standard ). But a challenge TIOCGWINSZ(or similar TIOCGSIZE) is widely available. Node probably relies on this in its checks.

This package checks the width of the standard output and does not do this, it checks the standard error: window-size (see source code ).

A similar question was asked earlier in How wide is the node.js console?

+2
source

All Articles