bug-ncurses
[Top][All Lists]
Advanced

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

Algorithm for "tput cols"


From: Grant Jenks
Subject: Algorithm for "tput cols"
Date: Mon, 20 Aug 2018 14:02:00 -0700

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 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:

$ 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?
5. ???

Is that right?

Thankful for any help,
Grant Jenks

reply via email to

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