[Tcsh] Multi-byte characters in promptchars

H.Merijn Brand tcsh at tux.freedom.nl
Fri Sep 20 08:46:49 UTC 2024


On Fri, 12 Apr 2024 12:15:18 +0300, Kimmo Suominen <kim at netbsd.org> wrote:

> On Fri, Apr 05, 2024 at 12:08:59PM +0200, H.Merijn Brand wrote:
> > That was not the tone I intended. I'm a volunteer myself and I did not
> > see it as a complaint. Sorry if that was not clear!  
> 
> Thank you for clarifying — I appreciate it.

New issue

With multibyte promptchars and a complicated prompt like

 promptchars ����
 prompt      xyz%{\e[47;34m0392\e[0m%} %U%m:%u%{\e[1m%}%/ %h %{\e[0;38;2;255;24;0m%}%#%{\e[0m%}

Positioning inside the line when editing still frequently messes up. A
control-R fixes that, but I guess it should be smooth

> > On Fri, 5 Apr 2024 12:47:05 +0300, Kimmo Suominen <kim at netbsd.org> wrote:  
> > > I think this part of the commit is your proposed fix:
> > > 
> > > diff --git a/ed.refresh.c b/ed.refresh.c
> > > index f1913801..bc902f5e 100644
> > > --- a/ed.refresh.c
> > > +++ b/ed.refresh.c
> > > @@ -1155,6 +1160,8 @@ CalcPosition(int w, int th, int *h, int *v)
> > >  	    *h += 4;
> > >  	    break;
> > >  	case NLSCLASS_ILLEGAL2:
> > > +	    *h += NLSCLASS_ILLEGAL_SIZE(w);
> > > +	    break;
> > >  	case NLSCLASS_ILLEGAL3:
> > >  	case NLSCLASS_ILLEGAL4:
> > >  	case NLSCLASS_ILLEGAL5:
> > > 
> > > Why does it only apply to NLSCLASS_ILLEGAL2?  
> > 
> > Because that was the smallest change required to make "it work", and I
> > do not understand the underlying internals, so keeping the scope as
> > small as possible was a way to do it the safest way possible.  
> 
> I gave this a try.  I noticed that the penguin is rendering across
> two columns.  If you use a character that renders in a single screen
> position, the cursor is placed off by one.  While this could be
> considered better than the original, which will be off by several
> column positions, it is clearly not correct.
> 
> You can reproduce with the hwair character:
> 
>     set promptchars=$'\U10348#'
> 
> versus the penguin character:
> 
>     set promptchars=$'\U1F427#'
> 
> Do we have something already that correctly provides the rendering width
> of the character?  Here is a Stack Overflow answer that points to using
> wcwidth(3) and wcswidth(3):
> 
>     https://stackoverflow.com/a/9145712/1511370
> 
>     https://man.netbsd.org/wcwidth.3
>     https://man.netbsd.org/wcswidth.3
> 
> I'm still not at all clear about the meanings of NSLCLASS_ILLEGAL*, but
> I'm guessing it is about the number of bytes taken to represent each
> character.  Which does not appear to equate with the rendering width of
> the characters.
> 
> And then should we also handle combining characters?  What if I wanted
> the Finnish flag in my prompt?
> 
>     echo $'\U1F1EB\U1F1EE'
> 
> Cheers,
> + Kimmo

-- 
H.Merijn Brand  https://tux.nl   Perl Monger   http://amsterdam.pm.org/
using perl5.00307 .. 5.37        porting perl5 on HP-UX, AIX, and Linux
https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.org
                           
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://mailman.astron.com/pipermail/tcsh/attachments/20240920/672c6e00/attachment.asc>


More information about the Tcsh mailing list