Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle xterm normal/reset escape sequence #72

Closed
dosisod opened this issue Mar 1, 2023 · 5 comments
Closed

Handle xterm normal/reset escape sequence #72

dosisod opened this issue Mar 1, 2023 · 5 comments

Comments

@dosisod
Copy link

dosisod commented Mar 1, 2023

I recently found out that xterm uses a weird escape sequence for the normal/reset sequence (aka sgr0). Most terminals use \e[0m, but xterm uses \e(B\e[m:

$ env TERM=st-256color tput sgr0 | xxd
00000000: 1b5b 306d                                .[0m
$ env TERM=xterm tput sgr0 | xxd
00000000: 1b28 421b 5b6d                           .(B.[m

Here is a small repro:

<html>

<head>
<script src="./ansi_up.js"></script>
</head>

<body>
<pre id="console"></pre>

<script>
const ansi_up = new AnsiUp();

const colors = "\033[1m\033[32mABC";

const xterm = "\033(B\033[mDEF\n";
const notXterm = "\033[0mDEF\n";

const html = ansi_up.ansi_to_html(colors + xterm + colors + notXterm);

document.getElementById("console").innerHTML += html;
</script>
</body>
</html>

And this is what it is displaying:

image

They both reset the color, though the (B bit shouldn't be there in the top line.

@drudru
Copy link
Owner

drudru commented Mar 1, 2023

I don’t think this is a common sequence.
Most apps have moved away from using the term cap database. They usually conform to a popular, common subset.

I personally use xterm-256 in tmux.

what app is sending this sequence?

still, if it is easy, then I don’t see why not.

@dosisod
Copy link
Author

dosisod commented Mar 1, 2023

The program in question is Mypy, specifically this line:

        normal = curses.tigetstr("sgr0")

I might open an issue/PR about replacing the curses calls with hardcoded escapes, but I suspect there are lots of other apps out there that are using curses for their escape sequences. A search with grep.app shows about ~160 open source Python repos are using the curses.tigetstr() function.

And I agree that if it is easy to add then it should be added just for better compatibility/coverage.

@drudru
Copy link
Owner

drudru commented Mar 9, 2023

Looking at this today…

@drudru
Copy link
Owner

drudru commented Mar 9, 2023

So, the sequence ESC ( C is actually resetting the character set to USASCII.
ESC ( A - is United Kingdom, C is Finnish.
Interesting.
I think the best strategy is to just ignore it. The data should be UTF8 already.

@dosisod
Copy link
Author

dosisod commented Mar 10, 2023

I agree, ignoring it is probably best.

@drudru drudru closed this as completed in 94cc84b Mar 16, 2023
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

No branches or pull requests

2 participants