# Normally returns the number of columns on the output tty. # Return 0 if output isn't a tty. # Returns undef if it's unable to find the width. sub tty_columns { return 0 unless -t STDOUT; my $result; # The following works on linux, but seems to fail on freebsd. # It works properly if the user resizes the terminal window while the program is running. if (eval "require 'sys/ioctl.ph'") { eval { # All of the dies on the next few lines will be caught by the eval{}. die unless defined &TIOCGWINSZ; open(TTY, "+