Re: Cursing the tput utility - the penguin strikes again

From: Daniel Tameling <tamelingdaniel_at_gmail.com>
Date: Thu, 23 Feb 2023 18:29:36 UTC
On Thu, Feb 23, 2023 at 04:45:21PM +0000, Frank Leonhardt wrote:
> I'm looking at another documentation snafu here.
> 
> So there's a tput utility for controlling the terminal in BSD. It takes
> "attributes" and arguments and outputs whatever control codes are needed to
> make the terminal do what you need in a portable way (switch to bold, move
> the cursor, clear to EOL or whatever). It doesn't matter if you're using an
> VT52 terminal or xterm - tput does the translation.
> 
> What the man page talks about as "attributes" are actually tcap codes -
> there's a list of them under "man 5 terminfo". So, to move the cursor to the
> top left use "tcap cm 0 0 " - "cm" being the tcap code for Cursor Move. The
> location and format of the database in the man page is way off mark, but
> never mind.
> 
> So what's my problem?
> 
> Well use the tcap utility on non-BSD platforms and it suddenly doesn't work.
> It turns out that the penguinistas thought using the "Cap Name" instead of
> the "TCap Code" was a good idea. Some of the codes are the same, some are
> not. In fact most are not.
> 
> So for example, "cm" becomes "cup", and "ce" (Clear End-of-line) is "el". On
> a Linux you probably need to use "tcap cup 0 0" instead of "tcap cm 0 0.
> 
> So my question is, assuming one wants one's scripts to be compatible with
> Linux, what's the best way of going about it? Is there some new
> platform-independent way of doing this I'm too old to know about, or do you
> really have to write shell scripts to cope with both by defining the code to
> use up front based on the output of uname?
> 
> I can figure this out - I just want to know if there's a "best practice"
> solution before rolling my own. If anyone reading expresses an interest I
> might put the best answer I can find in a blog post.
> 
> Thanks, Frank.
> 
> 
> 

Did you try using the tput from devel/ncurses instead? I once ran into
a similar problem and if I remember correctly that one works with the
same options as on Linux because it's the one installed there. And it
is frequently already installed as a dependency; the problem is just
that the FreeBSD tput is earlier in PATH.

--
Kind regards,
Daniel