[Top][All Lists]

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

Re: Algorithm for "tput cols"

From: Thomas Dickey
Subject: Re: Algorithm for "tput cols"
Date: Tue, 21 Aug 2018 05:04:07 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

On Mon, Aug 20, 2018 at 02:02:00PM -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?

It's a reduced form of the screensize-detection used for ncurses
(tput doesn't have options to alter its behavior with use_env or use_tioctl).

If there were much to add, I'd suppose it would be in the tput manual page.

But in the current manpage, while I've given some attention to
the relationship versus tset, I've not written a special section for
the special cases where tput adds/modifies information from the
terminfo database -- it's scattered across a few pages (look in
ncurses for COLUMNS, use_env, use_tioctl).
> I tried looking through the sources of tput.c but got lost looking for
> _nc_get_hash_table(termcap) where I thought it might be found. Some
> experiments I ran:

lib_setup.c is the place to look.

ncurses gets the terminfo database values (if any), tries to get the
value using something like

ioctl(0, TIOCGWINSZ, ...)

and may override that using the $COLUMNS environment variable.

> $ tput cols
> 120
> $ COLUMNS=99 tput cols
> 99
> $ COLUMNS="" tput cols
> 120
> $ COLUMNS="" tput cols | cat
> 120
> $ echo | COLUMNS="" tput cols | cat
> 120
> $ echo | COLUMNS="" tput cols 2>&1 | cat
> 120
> So as best I can tell, the algorithm is:
> 1. COLUMNS env var
> 2. stdout term size
> 3. stderr term size?
> 4. stdin term size?

The order's not right - in progs/tty_settings.c,
I have stderr first, then stdout and stdin.

The environment variable is checked last.

> 5. ???
> Is that right?
> Thankful for any help,
> Grant Jenks

> _______________________________________________
> Bug-ncurses mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/bug-ncurses

Thomas E. Dickey <address@hidden>

Attachment: signature.asc
Description: Digital signature

reply via email to

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