From nobody Thu Feb 23 16:45:21 2023 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PMzRG6f7Hz3sDBD for ; Thu, 23 Feb 2023 16:45:30 +0000 (UTC) (envelope-from freebsd-doc@fjl.co.uk) Received: from bs1.fjl.org.uk (bs1.fjl.org.uk [84.45.41.196]) by mx1.freebsd.org (Postfix) with ESMTP id 4PMzRG14ZZz3QJB for ; Thu, 23 Feb 2023 16:45:29 +0000 (UTC) (envelope-from freebsd-doc@fjl.co.uk) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of freebsd-doc@fjl.co.uk designates 84.45.41.196 as permitted sender) smtp.mailfrom=freebsd-doc@fjl.co.uk; dmarc=none Received: from [192.168.1.126] (host81-129-137-223.range81-129.btcentralplus.com [81.129.137.223]) (authenticated bits=0) by bs1.fjl.org.uk (8.14.4/8.14.4) with ESMTP id 31NGjMOh039803 for ; Thu, 23 Feb 2023 16:45:22 GMT (envelope-from freebsd-doc@fjl.co.uk) Message-ID: <974a81c2-a92d-7f94-5f96-869bddfe21f3@fjl.co.uk> Date: Thu, 23 Feb 2023 16:45:21 +0000 List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Content-Language: en-GB To: freebsd-questions@freebsd.org From: Frank Leonhardt Subject: Cursing the tput utility - the penguin strikes again Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [-2.19 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; NEURAL_HAM_SHORT(-0.99)[-0.987]; R_SPF_ALLOW(-0.20)[+ip4:84.45.41.196]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_SPAM_LONG(0.00)[0.000]; R_DKIM_NA(0.00)[]; MLMMJ_DEST(0.00)[freebsd-questions@freebsd.org]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:25577, ipnet:84.45.0.0/17, country:GB]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; DMARC_NA(0.00)[fjl.co.uk]; RCPT_COUNT_ONE(0.00)[1]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; MID_RHS_MATCH_FROM(0.00)[] X-Rspamd-Queue-Id: 4PMzRG14ZZz3QJB X-Spamd-Bar: -- X-ThisMailContainsUnwantedMimeParts: N 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.