On Aug 7, 3:55 pm, James Edward G. II [email protected]
wrote:
between releases), but that’s easier than parsing stdout for each
I don’t see that as any more maintenance than finding the magic
number and I know how to ask users to help me do the former.
Ronald parsed the output for Solaris with a single trivial Regexp, so
that didn’t feel like a significant hurdle to me.
In short, I’m comfortable with the stty approach. So far I haven’t
seen it blow up in anyway that I feel we would escape using ioctl().
Fair enough.
I thought I’d take a moment to explain that code a bit better. I
figure it might make it seem less opaque to you, and perhaps others
who stumble onto this thread later on will find it useful.
First, the code supplied above requires visually inspecting the
termios.h file on your system (yep, sorry, no way around that). It’s
probably under /usr/include or /usr/include/sys (or you can probably
find its declaration online). That’s where I got the value for
TIOCGWINSZ - it’s a #define’d value.
Moving on, I realized that the row and column data (along with the
xpixel and ypixel data) is stored in structure called ‘winsize’. It’s
declared like so:
/* Windowing structure to support JWINSIZE/TIOCSWINSZ/TIOCGWINSZ /
struct winsize {
unsigned short ws_row; / rows, in characters /
unsigned short ws_col; / columns, in character /
unsigned short ws_xpixel; / horizontal size, pixels /
unsigned short ws_ypixel; / vertical size, pixels */
};
That’s why we defined the ‘buf’ like this:
buf = [0, 0, 0, 0].pack(‘SSSS’)
That says give me a data buffer large enough to hold four unsigned
short integers. We could just as well have done “buf = 0.chr * 8”, but
the above notation is more explicit, to C programmers anyway, about
what that ‘buf’ really is, i.e. a data buffer large enough to hold a
struct with 4 members.
We then pass ‘TIOCGWINSZ’ and ‘buf’ as arguments to $stdin.ioctl. The
buf is passed by reference, meaning it will be filled with the
appropriate values after the call.
After ioctl has been called we have to unravel the buf the same way we
created it. That’s how we end up with this bit:
rows, cols, xpixels, ypixels = buf.unpack(‘SSSS’)
Hope that helps.
Dan