Subject: Re: bug#78807: 31.0.50; Wave underline set wrongly

From: Ergus <[email-masked]>
Date: Sun, 22 Jun 2025 18:13:01 +0200

Hi again Eli:

On Sun, Jun 22, 2025 at 08:33:50AM +0300, Eli Zaretskii wrote:
>> Date: Sun, 22 Jun 2025 01:44:39 +0000 (UTC)
>> From: Ergus <[email-masked]>
>> Cc: "[email-masked]" <[email-masked]>
>>
>> As far as I know the check for wave underline in terminfo may look for Smulx
>>
>> I tried: `infocmp -1 | grep -E 'Smulx|Su|cul'`
>>
>> and: `tigetstr("Smulx")` in a C snippet
>>
>> and none of them return positive.
>>
>> The function mentions that it uses some heuristics and that may be the problem?
>
>This is what we do:
>
>    /* Styled underlines.  Support for this is provided either by the
>       escape sequence in Smulx or the Su flag.  The latter results in a
>       common default escape sequence and is not recommended.  */
>  #ifdef TERMINFO
>    tty->TF_set_underline_style = tigetstr ("Smulx");
>    if (tty->TF_set_underline_style == (char *) (intptr_t) -1)
>      tty->TF_set_underline_style = NULL;
>  #else
>    tty->TF_set_underline_style = tgetstr ("Smulx", address);
>  #endif
>    if (!tty->TF_set_underline_style && tgetflag ("Su"))
>      /* Default to the kitty escape sequence.  See
>	 https://sw.kovidgoyal.net/kitty/underlines/.  */
>      tty->TF_set_underline_style = "\x1b[4:%p1%dm";
>
>    if (tty->TF_set_underline_style)
>      /* Standard escape sequence to set the underline color.
>	 Requires a single parameter, the color index.  */
>      tty->TF_set_underline_color = "\x1b[58:2::%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%dm";
>

As you can see in the line command I shared before: infocmp -1 | grep -E 'Smulx|Su|cul'

I already ckeck for the Su, Smulx and tmux is not returning a fake
possitive it is actually not returning anything. Which means that
underline styles are not supported.

>If tmux doesn't support this (again, please ask the tmux developers),
>then we need a way to detect tmux and avoid the above.

But I think that tmux is working fine, see bellow.

>But I'm surprised that no one has reported this till now.

Maybe because the issue is just a missing wave underscore only set in a
few faces. And some themes already overrides those faces to use normal
underline. Plus most users these days use emacs gui not -nw.

> Perhaps you need to upgrade your tmux?

Just tested the tmux master branch and it is the same.

This code:

```
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <term.h>
#include <unistd.h>

int main(void) {
     // Setup terminfo for the terminal from $TERM
     int errret;
     if (setupterm(NULL, STDOUT_FILENO, &errret) != OK) {
         fprintf(stderr, "Error: Could not initialize terminfo (code %d)\n", errret);
         return 1;
     }

     // Standard underline enter/exit
     char *smul = tigetstr("smul");   // start underline
     char *rmul = tigetstr("rmul");   // end underline

     // Extended underline mode (not standard, but defined in newer terminfo entries)
     char *smulx = tigetstr("Smulx"); // start underline with extended attributes

     int Su = tgetflag ("Su");

     printf("smul  (start underline): %s\n", (smul == (char *)-1 || smul == NULL) ? "Not available" : "Available");
     printf("rmul  (end underline)  : %s\n", (rmul == (char *)-1 || rmul == NULL) ? "Not available" : "Available");
     printf("Smulx (extended underline): %s\n", (smulx == (char *)-1 || smulx == NULL) ? "Not available" : "Available");
     printf("Su: %s\n", Su);

     return 0;
}
```

Outputs:

```
smul  (start underline): Available
rmul  (end underline)  : Available
Smulx (extended underline): Not available
Su: (null)
```

I could have something missing in the setupterm call, but this seems
correctly reporting NOT extended underline support.

So, maybe the issue is somewhere else? Why is emacs reporting wave
support?

Best,
Ergus