tput ed is empty

Apple configured ncurses with termcap support (in addition to the default terminfo):

  • config.status file showing the configure options.
  • infocmp calls _nc_read_file_entry to obtain its data.
  • tput calls setupterm, which goes to _nc_read_entry, which calls _nc_read_tic_entry, which does call _nc_read_file_entry
  • if there's a problem in _nc_read_tic_entry, then _nc_read_entry falls back to the termcap support (see read_entry.c).

Since that's ten-year-old code, the possible problem in _nc_read_tic_entry may have been fixed a while back.

For instance, I have MacPorts installed, and that works properly, while Apple's version does not. Here is a top-level script that I used to investigate the problem with:

#!/bin/sh
unset TERMINFO
unset TERMINFO_DIRS
export TERM=xterm-256color
#export PATH=/usr/bin:$PATH
echo TERMCAP
infocmp -CrTt1 | grep -E ':..=.*:' | sed -e 's/^    ://' -e 's/=.*//' | xargs -n 1 /tmp/test-tput
echo TERMINFO
infocmp -1 | grep -E '^ .*=.*,' | sed -e 's/^   //' -e 's/=.*//' | xargs -n 1 /tmp/test-tput

(commenting/uncommenting the PATH to select between the two), and that called a second script /tmp/test-tput to show the values:

#!/bin/bash
tput "$1" >/dev/null 2>/dev/null || exit
echo -n "CAP:$1 "
tput "$1" 2>/dev/null
echo

The behavior in ncurses 5.7 was a bug introduced in 1999

    + modify tput to accept termcap names as an alternative to terminfo
      names (patch by Jeffrey C Honig).

and fixed in 2009:

    + change order of lookup in progs/tput.c, looking for terminfo data
      first.  This fixes a confusion between termcap "sg" and terminfo
      "sgr" or "sgr0", originally from 990123 changes, but exposed by
      20091114 fixes for hashing.  With this change, only "dl" and "ed" are
      ambiguous (Mandriva #56272).

Apple's ncurses 5.7 is about a year older than that fix.


Are more googling and scouring the documentation (mainly terminfo), I finally figured out that I need to fall back to the older termcap code since the capname is not supported for all terminfo capabilities.

ed=$(tput ed || tput cd)