[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Algorithm for "tput cols"

From: Timothy Allen
Subject: Re: Algorithm for "tput cols"
Date: Tue, 21 Aug 2018 11:04:32 +1000

On Mon, 2018-08-20 at 14:02 -0700, Grant Jenks wrote:
> First time poster. Many thanks for ncurses!
> Someone recently showed me that "tput cols" is quite clever about
> determining the number of columns supported by the terminal. Is
> the algorithm for doing so documented anywhere?

I haven't checked the tput source-code myself, but there's another
source you may not have considered: any process at any time can open
/dev/tty to get a handle to the terminal they're running in (if any),
regardless of where stdin, stdout, stderr or any other handles are
connected. So, the "algorithm" probably looks like:

1. check $COLUMNS
2. open("/dev/tty") and use the TIOCGWINSZ ioctl to get the size
3. look up $TERM in the terminfo database, and use that size.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]