Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script that runs a series of scripts numbered 001,002,003,004... etc down to 041 right now, will be more in the future - and these scripts them selves use some cursor control to print a progress bar and other status information and get the width and height of the terminal from tput cols and tput lines respectively.

Without rewriting the sub-scripts, I would like to reserve one line at the bottom for overall status information for the outer script. I was curious if there was a way to set what tput replies for lines and cols.

There must be a way because tmux achieves it. I was thinking there may be an environmental variable but the only change I can see that tmux makes when running env is setting the $TERM to screen.

Any help would be greatly appreciated

share|improve this question
    
WRT tmux, the stuff in that is running inside tmux, which provides multiple shells and windows. Ie, it is not doing this via shell commands. So going that route means writing a pretty serious application. – goldilocks Dec 19 '12 at 19:27
    
Well it has to be altering something tput is reading, I tried looking up the source of tput but didn't understand it at all – donatJ Dec 19 '12 at 20:36
up vote 2 down vote accepted

The following will let you customize the number of lines and cols tput returns

export LINES=1000
export COLUMNS=1000
share|improve this answer

Reading the source would be definitive, but for the fainthearted, the manual is the place to go. If there is no command-line option, the terminal database in combination with environment variables will provide your script with whatever it might need:

Searching for enlightenment, you might try the ncurses manual page.

  • In the section on Environment, it lists LINES and COLUMNS.
  • In LINES, it just says to see COLUMNS.
  • COLUMNS gives more information:

Specify the width of the screen in characters. Applications running in a windowing environment usually are able to obtain the width of the window in which they are executing. If neither the COLUMNS value nor the terminal's screen size is available, ncurses uses the size which may be specified in the terminfo database (i.e., the cols capability).

Now, for this question, it would have been nice if the manual page were more direct, saying that tput uses tputs for output and also uses setupterm for initialization. Occasionally (when this information is readily available in the changelog) no one notices that it is not explicit in the manual. For instance this item from 2002:

    + modify setupterm() to ensure that it initializes the baudrate, for
      applications such as tput (report by Frank Henigman).

Back to the thread:

  • The Initialization section of curs_terminfo(3x) describes setupterm, noting
  • in the normal case, where use_env has not been called, setupterm allows the LINES and COLUMNS variables to override the terminal database values.
  • The use_env manual page reiterates that, as well as commenting that the values might be obtained from the operating system.
  • Again, the changelog mentions that tput does this (gets the values from the operating system), e.g., this from 2007:

    + restore a call to obtain screen-size in _nc_setupterm(), which
      is used in tput and other non-screen applications via setupterm()
      (Debian #433357, reported by Florent Bayle, Christian Ohm,
      cf: 20070310).
    

In summary, the existing documentation provides answers to almost all questions about the behavior of ncurses, but you have to do some reading.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.