<div dir="ltr">Fair enough. I'll make a branch from my latest windows branch. It will serve as a proof-of-concept for the fix and if it works for you, I'll spend some time to clean up and merge everything properly back to upstream.<div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Sep 21, 2024 at 3:42 AM H.Merijn Brand <<a href="mailto:tcsh@tux.freedom.nl">tcsh@tux.freedom.nl</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri, 20 Sep 2024 09:30:41 -0700, Amol Deshpande <<a href="mailto:amol.vinayak.deshpande@gmail.com" target="_blank">amol.vinayak.deshpande@gmail.com</a>> wrote:<br>
<br>
> So, this is how the Windows version works and if you can tell me that this<br>
> applies to Linux as well, I can hopefully whip up a patch over the weekend.<br>
> <br>
> If the prompt string being output is UTF-8, tcsh is still putting each byte<br>
> into a 32-bit int when WIDE_CHAR is set.<br>
> <br>
> Therefore, it may actually be 2 Chars (or 3, or 4) in the prompt that are<br>
> consumed for displaying an emoji or whatever.<br>
> However, the code in ed.refresh.c (RefreshPromptpart) is written to assume<br>
> each Char is an independent byte.<br>
> <br>
> So, in addition to wcwidth to find the length of the output, NLSWidthMB<br>
> should also report how many Chars of the input string it consumed to<br>
> represent the emoji. (line 318)<br>
> <br>
> We should then increment cp by "+= consumed" in the above function while<br>
> looping through the buffer, instead of by just 1. (line 320)<br>
> <br>
> Does that sound right or am I missing something ?<br>
<br>
Knowing Unicode as much as I do (way insufficient), than I/we will most<br>
likely miss something.<br>
<br>
That said, you could start a branch with what you think is correct, and<br>
I will be more than happy to test that with my insane prompts<br>
<br>
> -amol<br>
> <br>
> On Fri, Sep 20, 2024 at 7:38 AM Kimmo Suominen <<a href="mailto:kim@netbsd.org" target="_blank">kim@netbsd.org</a>> wrote:<br>
> <br>
> > On Fri, Sep 20, 2024 at 10:46:49AM +0200, H.Merijn Brand wrote: <br>
> > > With multibyte promptchars and a complicated prompt like<br>
> > ><br>
> > > promptchars 🐧🔐<br>
> > > prompt xyz%{\e[47;34m0392\e[0m%} %U%m:%u%{\e[1m%}%/ %h %{\e[0;38;2;255;24;0m%}%#%{\e[0m%} <br>
> > ><br>
> > > Positioning inside the line when editing still frequently messes up. A<br>
> > > control-R fixes that, but I guess it should be smooth <br>
> ><br>
> > I think the issue is highlighted by this question I made:<br>
> ><br>
> > On Fri, 5 Apr 2024 12:47:05 +0300, Kimmo Suominen <<a href="mailto:kim@netbsd.org" target="_blank">kim@netbsd.org</a>><br>
> > wrote: <br>
> > > Why does it only apply to NLSCLASS_ILLEGAL2? <br>
> ><br>
> > I think the whole logic there across the NLSCLASS_ILLEGALn cases is<br>
> > incorrect.<br>
> > <br>
> > > Do we have something already that correctly provides the rendering<br>
> > > width of the character? Here is a Stack Overflow answer that points<br>
> > > to using wcwidth(3) and wcswidth(3):<br>
> > ><br>
> > > <a href="https://stackoverflow.com/a/9145712/1511370" rel="noreferrer" target="_blank">https://stackoverflow.com/a/9145712/1511370</a><br>
> > ><br>
> > > <a href="https://man.netbsd.org/wcwidth.3" rel="noreferrer" target="_blank">https://man.netbsd.org/wcwidth.3</a><br>
> > > <a href="https://man.netbsd.org/wcswidth.3" rel="noreferrer" target="_blank">https://man.netbsd.org/wcswidth.3</a> <br>
> ><br>
> > I think the correct implementation needs to include the detection of the<br>
> > rendering width of the characters.<br>
> ><br>
> > + Kimmo<br>
<br>
-- <br>
H.Merijn Brand <a href="https://tux.nl" rel="noreferrer" target="_blank">https://tux.nl</a> Perl Monger <a href="http://amsterdam.pm.org/" rel="noreferrer" target="_blank">http://amsterdam.pm.org/</a><br>
using perl5.00307 .. 5.37 porting perl5 on HP-UX, AIX, and Linux<br>
<a href="https://tux.nl/email.html" rel="noreferrer" target="_blank">https://tux.nl/email.html</a> <a href="http://qa.perl.org" rel="noreferrer" target="_blank">http://qa.perl.org</a> <a href="https://www.test-smoke.org" rel="noreferrer" target="_blank">https://www.test-smoke.org</a><br>
<br>
</blockquote></div>