On 29/03/2024 21:59, Bruno Haible wrote:
Pádraig Brady wrote:
You could determine that programatically with something like:

if os.system(r'{ tput bold || tput md; } >/dev/null 2>&1') == 0:
    # enable bold output

As a matter of interest, where did you get the figure that
94% of users have a $TERM set to xterm.* ?

+def get_terminfo_string(capability: str) -> str:
+    '''Returns the value of a string-type terminfo capability for the current 
value of $TERM.
+    Returns the empty string if not defined.'''
+    value = ''
+    try:
+        value = sp.run(['tput', capability], stdout=sp.PIPE, 
stderr=sp.DEVNULL).stdout.decode('utf-8')
+    except Exception:
+        pass
+    return value

Might latin-1 be more appropriate here, to accept all byte sequences?

I used the following for example to see that xterm-8bit outputs an invalid 
utf-8 sequence:

  find /usr/share/terminfo -type f -printf '%f\n' | while read t; do
    echo -n $t; TERM=$t tput bold | od -An -tx1
  done | grep -v 1b

I know the code path isn't used for xterm.* and I don't want to cause any more 
complexity,
but was wondering all the same.

cheers,
Pádraig

Reply via email to