Skip to content

Add more underlines#120

Open
data-man wants to merge 1 commit intotermbox:masterfrom
data-man:more_underlines
Open

Add more underlines#120
data-man wants to merge 1 commit intotermbox:masterfrom
data-man:more_underlines

Conversation

@data-man
Copy link
Copy Markdown

Many modern terminal emulators support them.
For example, WezTerm.
The small test:

#define TB_IMPL
#define TB_OPT_ATTR_W 64
#include "termbox2.h"

int main(int argc, char **argv) {
    struct tb_event ev;
    int x = 0;
    int y = 0;

    tb_init();

    tb_printf(x,   y++, TB_GREEN, 0, "green hello from termbox");
    tb_printf(x,   y++, 0, 0, "width=%d height=%d", tb_width(), tb_height());

    tb_printf(x++, y++, TB_BLUE, 0, "Test styles:");

    tb_printf(x,   y++, TB_BOLD, 0,             "TB_BOLD");
    tb_printf(x,   y++, TB_UNDERLINE, 0,        "TB_UNDERLINE");
    tb_printf(x,   y++, TB_REVERSE, 0,          "TB_REVERSE");
    tb_printf(x,   y++, TB_ITALIC, 0,           "TB_ITALIC");
    tb_printf(x,   y++, TB_BLINK, 0,            "TB_BLINK");
    tb_printf(x,   y++, TB_HI_BLACK, 0,         "TB_HI_BLACK");
    tb_printf(x,   y++, TB_BRIGHT, 0,           "TB_BRIGHT");
    tb_printf(x,   y++, TB_DIM, 0,              "TB_DIM");
    tb_printf(x,   y++, TB_STRIKEOUT, 0,        "TB_STRIKEOUT");
    tb_printf(x,   y++, TB_UNDERLINE_2, 0,      "TB_UNDERLINE_2");
    tb_printf(x,   y++, TB_OVERLINE, 0,         "TB_OVERLINE");
    tb_printf(x,   y++, TB_INVISIBLE, 0,        "TB_INVISIBLE");

    tb_printf(x,   y++, TB_DOUBLY_UNDERLINE, 0, "TB_DOUBLY_UNDERLINE");
    tb_printf(x,   y++, TB_CURLY_UNDERLINE, 0,  "TB_CURLY_UNDERLINE");
    tb_printf(x,   y++, TB_DOTTED_UNDERLINE, 0, "TB_DOTTED_UNDERLINE");
    tb_printf(x,   y++, TB_DASHED_UNDERLINE, 0, "TB_DASHED_UNDERLINE");

    tb_printf(0,   y++, 0, 0, "press any key...");

    tb_present();

    tb_poll_event(&ev);

    tb_shutdown();

    return 0;
}
Screenshot_20251021_101258

Copy link
Copy Markdown
Contributor

@adsr adsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @data-man. This looks good to me as long as these no-op on unsupported terminals instead of breaking things. I tested in xterm (not supported but doesn't break), the Linux console (same), and vte (works).

It would be a good exercise to go through popular terminal emulators to get a better sense of what else we're missing if anything. I'll leave this open to see if anyone else has comments.

This also reminds me I have a feature branch for user-defined style attributes that use the upper 32 bits of the fg and bg. I'll post a PR. Basically, if a high bit is set, termbox will ignore all the bits above and including TB_STRIKEOUT and instead invoke a callback. This gives the caller 31 bits to play with. It would give us an escape hatch for supporting anything we might miss, so long as it can be expressed in 31 bits. It would be a clean way of handling issue #107 for example.

Comment thread termbox2.h Outdated
@data-man
Copy link
Copy Markdown
Author

It would be a good exercise to go through popular terminal emulators to get a better sense of what else we're missing if anything.

https://en.wikipedia.org/wiki/ANSI_escape_code#Select_Graphic_Rendition_parameters

For example:

58 | Set underline color | Not in standard; implemented in Kitty, VTE, mintty, and iTerm2.
59 | Default underline color | Not in standard; implemented in Kitty, VTE, mintty, and iTerm2.

At least, 58 and 59 also implemented in Contour, Konsole and WezTerm.

73 | Superscript | Implemented only in mintty
74 | Subscript | Implemented only in mintty

73 and 74 also implemented in WezTerm.

@txgk
Copy link
Copy Markdown
Contributor

txgk commented Oct 26, 2025

This looks good to me as long as these no-op on unsupported terminals instead of breaking things. I tested in xterm (not supported but doesn't break), the Linux console (same), and vte (works).

test-alacritty test-foot test-kitty

Alacritty, foot and kitty support these, although foot fallbacks to regular underline attribute when I run it with screen for TERM (i.e. tmux session).

@data-man
Copy link
Copy Markdown
Author

It would be a good exercise to go through popular terminal emulators to get a better sense of what else we're missing if anything.

My most desired feature: support https://sw.kovidgoyal.net/kitty/keyboard-protocol.

In addition to kitty, this protocol is also implemented in:

Libraries implementing this protocol:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants