Pixel <[EMAIL PROTECTED]> writes:
> another reason is that to nicely wrap the list you need to know the terminal
> size which is not that easy to do.
Why?
========== C ===============
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
int main() {
struct winsize winsize;
int fd = open(ttyname(1), O_RDONLY, 0);
if (fd < 0) {
perror("open stdout-tty");
exit(errno);
}
if (ioctl(fd, TIOCGWINSZ, &winsize)) {
perror("failed to get winsize");
exit(errno);
}
printf("size of terminal launching this app\n");
printf("rows %d columns %d\n", winsize.ws_row, winsize.ws_col);
exit(0);
}
============================
========== Ruby ============
buf = "\0" * 8
$stdout.ioctl(0x5413, buf)
row, col = buf.unpack("v2")
puts "size of terminal launching this app"
puts "rows #{row} columns #{col}"
============================
--
Guillaume Cottenceau - http://people.mandrakesoft.com/~gc/