bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gnulib-tool.py: Display specified modules in bold.


From: Bruno Haible
Subject: Re: gnulib-tool.py: Display specified modules in bold.
Date: Sun, 31 Mar 2024 00:38:36 +0100

Hi Pádraig,

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

Personal guesses / estimations :-D.

> > +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?

But it would be output in UTF-8 later, during print(...). therefore
converting to a string here is inappropriate.

I tried to return a byte array here instead of a string, but this led to
ugly code elsewhere.

> 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.

If such a TERM value is used, the decode('utf-8') step will fail, thus the
value returned from get_terminfo_string will be empty, and bold-face won't
work.

This is not perfect, but it is good enough. Often, it's necessary to say
"it's good enough" because otherwise I spend more and more time on a tiny
feature. I have verified that it works with all TERM values of all OSes
for which I have virtual machines (except for Solaris 11.4, as mentioned);
I'm not inclined in spending more time on it.

Bruno






reply via email to

[Prev in Thread] Current Thread [Next in Thread]