in reply to bulletproof way of finding size of terminal?

Can you believe this is a FAQ? :-)

Should be portable on POSIX, at least.

  • Comment on Re: bulletproof way of finding size of terminal?

Replies are listed 'Best First'.
Re^2: bulletproof way of finding size of terminal?
by FunkyMonk (Bishop) on Aug 31, 2007 at 19:36 UTC
    Here's a litle sub I wrote a while back. For once, I kept some decent comments on where I found it to work, and not work.
    # $ENV{COLUMNS} isn't set when running through putty (unless from with +in emacs) # GetTerminalSize returns 0 from emacs, but ok from putty # fallback to 72 if the other two methods fail sub get_terminal_width { -t STDOUT && return (GetTerminalSize)[0] || $ENV{COLUMNS} || 72; return 72; }

    The FAQ postings are the only thing I miss from clpmisc

      Hnmn...that doesn't work for me. The $ENV{COLUMNS} is, I think, guaranteed never to work, since COLUMNS isn't an environment variable. The (GetTerminalSize)[0] is, I assume, depending on some module?
        GetTerminalSize comes from Term::ReadKey that you've already mentioned.

        I wasn't proposing a solution, just stating some steps, and the problems that I faced, while trying to solve a similar problem.

        I was really trying to point out things that didn't work.

Re^2: bulletproof way of finding size of terminal?
by bcrowell2 (Friar) on Aug 31, 2007 at 22:23 UTC
    Aha -- interesting, thanks! The one thing that's a drag is that the ioctl method doesn't seem to work when you're ssh'd in (even though -T STDOUT is true). Other than that, it's exactly what I need.
        Interesting. I was actually trying to do it while ssh'd into a freebsd box, so maybe it just doesn't work on bsd?