frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Inspect ANSI control codes and escape sequences

https://ansi.tools
57•webpro•3d ago

Comments

webpro•3d ago
Working with and debugging ANSI control codes and escape sequences can be a challenge.

This free web-based tool helps to inspect the input, visualize colors and styling, and list control codes. By using a proper tokenizer and parser (not just regex hacks), it supports all sorts of control codes. The parser is open source and available too (find links in "about").

Type or paste text in the black text area, or try out the examples. Use the lookup table to filter & find specific codes.

Feedback welcome, I’d love to know what’s confusing, missing, or especially useful.

michaelmior•4h ago
Very cool! Seems like this should be a Show HN post.
JdeBP•4h ago
The revealing shibboleth is when people call it "ANSI". (-: "ANSI" is what people call it when they are working from paltry and incomplete samizdat doco of how this stuff works, from Microsoft's old ANSI.SYS appendix to its MS-DOS user manual, to innumerable modern WWW sites all repeating received wisdom.

The thing to remember is that the "E" in "ECMA" does not stand for "ANSI".

* https://ecma-international.org/publications-and-standards/st...

* https://ecma-international.org/publications-and-standards/st...

* https://www.itu.int/rec/T-REC-T.416-199303-I

If you read ECMA-35, you'll find that there's actually a whole system to escape sequences and control sequences. As I pointed out last month, it's often the case that people who haven't read ECMA-35 don't realize that parameter characters can be more than digits, don't handle intermediate characters, and don't grasp how DEC's question mark and SCO's equals sign fit into the overall picture. People who haven't read ECMA-48 and traced its history don't realize that there's subtlety to missing parameters in control sequences. And people who haven't read ITU/IEC T.416 do what many of us did years ago and get 24-bit colour wrong. Twice over.

* https://github.com/tattoy-org/tattoy/issues/105#issuecomment...

Other common errors include missing out on all of the other 7-bit aliases for C1 characters. Or not realising that the ECMA-35/ECMA-48 syntax allows for any control sequence to have sub-parameters, not just SGR. Or using regular expressions and pattern matching instead of a state machine. Only a state machine truly handles the fact that in the real world terminals allowed, and enacted, various C0 and C1 control characters in the middle of control sequences, as well as had ways of cancelling or restarting control sequences mid-sequence.

* https://github.com/jdebp/nosh/blob/trunk/source/ECMA48Decode...

But it gets even worse for a real world control sequence decoder.

In the real world, not only do terminals interpret the same control sequences, and their parameters, differently depending from whether the terminal is sending or receiving them; but several terminal emulators like the one in Interix, rxvt, the one built in to Linux, and even XTerm, send control sequences that not only break ECMA-35 but also conflict with received control sequences. So if one wants to be comprehensive and be cabable of decoding real data, one needs a switch to tell the program whether to decode the character stream as if it is being received by the terminal or as if it is being sent by the terminal.

* https://jdebp.uk/Softwares/nosh/guide/commands/console-decod...

Microsoft Terminal tries to do things properly, which many modern terminal emulators and tools do not, and handles this with two distinct entire state machines, one for input and one for output.

* https://github.com/microsoft/terminal/tree/main/src/terminal...

I handled it with a few goto statements and a handful of flags. (-:

* https://github.com/jdebp/nosh/blob/trunk/source/console-deco...

blueflow•3h ago
I think this rant is out-of-place here, type "\x1b[:<=>$t" and check for yourself. It parses correctly. You do learn about the allowed character ranges for CSI sequences from ECMA-48 only, not from the Microsoft docs, so i guess the author did their homework.
JdeBP•3h ago
That tells me that you are writing from ignorance, as for starters that's a truly pathetic test that even misses one of the characters that I explicitly mentioned above, let alone thoroughly tests the full range that the specs define. I had an actual poke around the parser code, in contrast to your superficial experimentation. (-: One can, with knowledge, actually find the point where the only three unusual characters that you in fact tested are special cased.
blueflow•2h ago
They are not special cased:

  https://github.com/webpro/ANSI.tools/blob/main/packages/parser/src/parsers/csi.ts#L12
The comment correctly identifies the 0x30-0x3f range as parameter bytes and the following as intermediate bytes. Both the range and the names for the bytes are matching ECMA-48 Chapter 5.4.

But you seem to think that everyone except yourself is incompetent, are you trying to make up for something?

JdeBP•57m ago
Of course they are. There's a file with all of the special cased constants in, named constants.ts.

Your superficial test tested all three of the special cases in the PRIVATE_OPENERS array, which is what the parser.ts code actually checks. DEC's question mark, which is special cased yet further off on its own, is in reality another "private opener", too, and it isn't limited to DEC (e.g. XQTMODKEYS), and neither does DEC not use the other non-digit parameter characters (e.g. DECDA3).

(There's a hypothesis that DEC's own state machine didn't care where these marker characters were, as it was a simple state machine that had to fit in ROM and probably just set a bitflag. A mistake that we're probably all still making is assuming that they only take effect when in the very first position.)

STRING_OPENERS is another widespread special casing that people do, treating ESC plus a few characters as special rather than handling all of the 7-bit aliases for the C1 characters as the general case.

You seem to think that people who share what the mistakes are and where they themselves have made these very mistakes over the years, to help other people not make them and so that the world continues to remember this hard-learned stuff, is somehow worthy of ad hominems, straw men, insults, and vilification right off the bat. That's a very poor show and you should be ashamed.

clucas•34m ago
> people who share what the mistakes are and where they themselves have made these very mistakes over the years, to help other people not make them and so that the world continues to remember this hard-learned stuff

But then we have this in your post:

> That tells me that you are writing from ignorance, as for starters that's a truly pathetic test

and

> I had an actual poke around the parser code, in contrast to your superficial experimentation.

Perhaps you really did intend for these lines to be helpful and informative? If so, I encourage you to have a moment of empathy for your interlocutor and ask yourself if talking this way is actually the best way to communicate and pass on this hard-earned knowledge.

> ad hominems, straw men, insults, and vilification

I didn't see this from the other poster. I did see it from you. As a disinterested third party, I'm just telling you, you come off way worse in this exchange. Good luck out there buddy.

webpro•6m ago
That's some interesting feedback, thanks for sharing. I'll see what I can extract and apply from it. Please bear with me, this is only my initial take on the whole concept (and as you point out, it isn't that trivial). Didn't have much examples to be inspired by, but we're on our way anyway.
webpro•4m ago
Thanks. Agreed. The way I see it, ignore the noise and there might be something in there.
mnurzia•4h ago
Neat tool, I could see this being handy for debugging TUI tools.

I noticed that it works with _escaped_ ESC characters ("\x1b", "\u001b", "\033") but it didn't recognize raw ESC characters that I had in my clipboard. It might be useful to support those (maybe highlight them similarly to how VS Code highlights whitespace characters). The characters show up as numbered unicode error glyphs (I'm on Firefox, if that helps)

ryan-c•4h ago
This is really cool - I've been experimenting with terminal escape sequences recently, and they go deep. Thanks for sharing! Get in touch (email in profile) if you'd like to collaborate.
webpro•12m ago
Thanks! It's all open source (including the tokenizer/parser), so feel free come collaborate on GitHub.
SpaceL10n•3h ago
The things they don't prepare you for in school...

I was working at my first job and we had a ColdFusion app that was displaying some data from the database. I get a ticket one day saying our search page would crash when searching for a very specific document. The other 1 million+ documents all loaded fine to our knowledge, so why this one?

I was pretty junior back then and feeling mighty defeated as to why I couldn't figure it out. I debugged every single line and condition, trying to find some reason. After ruling out the code as a culprit, I took the data we were loading and placed it into Notepad++. Don't remember why exactly. I was wracking my brain trying to come up with explanation and lazily moving the text cursor left and right through the text, mostly out of boredom and despair.

That's when I noticed that I had pressed the right arrow key in my keyboard and the text cursor position hadn't changed! I pressed it again and nothing. Again, nothin. It took eight key presses to move the text cursor from one letter in a word to the adjacent letter. I was utterly bamboozled. Why was the text cursor getting stuck in the middle of this word?!

Shortly thereafter, I discovered "Show all hidden characters" setting in the menu. I toggled it and sure enough there were little black boxes with weird three letter strings in them. NUL, ESC, and others - right where my cursor was getting hung up.

That was the day I learned about ANSI control characters and the importance of data sanitization.

tronster•3h ago
This is a fantastic web util; bookmarked for the future.

I wish I had this when I was making, [Dragon's Oven](https://tronster.itch.io/dragon). It was a lot of nights and weekends of tinkering with ANSI codes in Typescript. I learned a lot that surprised me, such as: most modern OS's still don't support 16m colors out of the box and that the default Linux shell doesn't support beyond 16 colors. Also no really good modern ANSI editors out there. I tried bringing back "TheDraw" in DosBOX for some art, but ended up using a mismatch of more modern utilities, false starting one of my own, and working on an image to ASCii/ANSI converter.

Maybe it's growing up in the BBS days, but something about ANSI is really charming.

prometheus76•2h ago
TheDraw was a cornerstone of my teenage years. I would log into different BBSs just to see their ANSI welcome screens, then I would try and re-create them to learn the art. It was a unique form of animation and I was hoping you had figured out how to get TheDraw working.

I also later used ANSI to make my own cool command line prompts in DOS and later, Linux.

codesnik•2h ago
I wonder how many languages have nice looking "\e" for "\u001b". ruby, perl, bash, anything else?
112233•1h ago
"\u001b[0m — reset" ... what? Why SGR is not called by name, while, e.g. CUU is? strange... According to which terminal or standard it interperts sequences?

Is this tool really helpful? It does look nice! But it does not help with the corneriest cases that would benefit from such tool the most.

webpro•17m ago
Got to start somewhere! Didn't see many examples to get inspired by either. Here's the full table: https://ansi.tools/lookup. This is my initial take on it. Please bring in the corneriest cases! It's open source so bug reports, RFCs and pull requests are most welcome.
gwbas1c•1h ago
I was a teenager when BBS's were popular. I still sometimes think I would enjoy writing an ANSI parser.
taviso•56m ago
I've used the tool sequin in the past to debug issues: https://github.com/charmbracelet/sequin

It worked great for me, seems much easier to debug logs directly in the terminal.

webpro•15m ago
Thanks for sharing, haven't seen that one yet. Will see if I can borrow ideas from it.
teddyh•29m ago
No support for blinking text.
webpro•14m ago
The parser has, but not the HTML renderer indeed. Using a third-party lib for that currently, but noticed the limitations too. Might replace it with my own!
teddyh•6m ago
Great! Next step: torturetest.vt
webpro•2m ago
There is https://github.com/webpro/ANSI.tools/blob/main/packages/pars... and others
FlyingAvatar•19m ago
I would have loved this in 1993. Not that I don't now, but I would have had a real use for it then.
webpro•16m ago
At least I tried to make it look like a 1993 website

lsr: ls with io_uring

https://tangled.sh/@rockorager.dev/lsr
101•mpweiher•2h ago•55 comments

CP/M Creator Gary Kildall's Memoirs Released as Free Download

https://spectrum.ieee.org/cpm-creator-gary-kildalls-memoirs-released-as-free-download
129•rbanffy•4h ago•37 comments

Ask HN: Any active COBOL devs here? What are you working on?

95•_false•1h ago•65 comments

An average human breathes out roughly 1kg of carbon dioxide a day

https://twitter.com/ID_AA_Carmack/status/1945948569246027934
12•tosh•56m ago•17 comments

When Root Meets Immutable: OpenBSD Chflags vs. Log Tampering

https://rsadowski.de/posts/2025/openbsd-immutable-system-logs/
87•todsacerdoti•6h ago•34 comments

Fully homomorphic encryption and the dawn of a private internet

https://bozmen.io/fhe
329•barisozmen•11h ago•138 comments

NYPD Bypassed Facial Recognition Ban to ID Pro-Palestinian Student Protester

https://www.thecity.nyc/2025/07/18/nypd-fdny-clearview-ai-ban-columbia-palestinian-protest/
86•dataflow•1h ago•35 comments

I'm Peter Roberts, immigration attorney who does work for YC and startups. AMA

2•proberts•17m ago•1 comments

HathiTrust Digital Library – books online

https://www.hathitrust.org/
18•djoldman•3d ago•5 comments

French villages have no more drinking water. The reason? PFAS pollution

https://www.lemonde.fr/en/environment/article/2025/07/18/these-french-villages-have-no-more-drinking-water-the-reason-pfas-pollution_6743479_114.html
39•rawgabbit•52m ago•18 comments

Exposing the Unseen: Mapping MCP Servers Across the Internet

https://www.knostic.ai/blog/mapping-mcp-servers-study
9•gepeto42•1h ago•1 comments

Resolve (YC W15) Is Hiring an Operations and Billing Lead for Construction VR

1•ugolino91•3h ago

Psilocybin decreases depression and anxiety in cancer patients (2016)

https://pmc.ncbi.nlm.nih.gov/articles/PMC5367557/
151•Bluestein•4h ago•112 comments

Hundred Rabbits – Low-tech living while sailing the world

https://100r.co/site/home.html
84•0xCaponte•3d ago•16 comments

15 Years of Building Jefit

https://www.jefit.com/our-story
22•jasong•3d ago•15 comments

ChatGPT agent: bridging research and action

https://openai.com/index/introducing-chatgpt-agent/
642•Topfi•22h ago•434 comments

Mistral Releases Deep Research, Voice, Projects in Le Chat

https://mistral.ai/news/le-chat-dives-deep
608•pember•1d ago•138 comments

What’s on offer at a luxury Bay Area longevity clinic

https://www.sfchronicle.com/health/aging-longevity/article/human-longevity-health-clinic-20277643.php
18•brandonb•1h ago•15 comments

Inspect ANSI control codes and escape sequences

https://ansi.tools
58•webpro•3d ago•29 comments

Row Polymorphic Programming

https://www.stranger.systems/posts/by-slug/row-polymorphic-programming.html
10•todsacerdoti•3d ago•0 comments

Travelers to the U.S. must pay a new $250 'visa integrity fee' – what to know

https://www.cnbc.com/2025/07/18/visa-integrity-fee-what-to-know-about-new-travel-fee-to-enter-the-us-.html
17•koolba•1h ago•0 comments

My experience with Claude Code after two weeks of adventures

https://sankalp.bearblog.dev/my-claude-code-experience-after-2-weeks-of-usage/
331•dejavucoder•20h ago•288 comments

NIH is cheaper than the wrong dependency

https://lewiscampbell.tech/blog/250718.html
254•todsacerdoti•12h ago•165 comments

Perfume reviews

https://gwern.net/blog/2025/perfume
276•surprisetalk•1d ago•148 comments

All AI models might be the same

https://blog.jxmo.io/p/there-is-only-one-model
253•jxmorris12•21h ago•113 comments

TCP-in-UDP Solution (eBPF)

https://blog.mptcp.dev/2025/07/14/TCP-in-UDP.html
57•todsacerdoti•3d ago•14 comments

Self-taught engineers often outperform (2024)

https://michaelbastos.com/blog/why-self-taught-engineers-often-outperform
371•mbastos•1d ago•285 comments

I Never Cared Much for Swords. Then I Had to Fight with One

https://thewalrus.ca/i-never-cared-much-for-swords-then-i-had-to-fight-with-one/
27•pseudolus•2h ago•25 comments

Hand: open-source Robot Hand

https://github.com/pollen-robotics/AmazingHand
413•vineethy•1d ago•103 comments

My favorite use-case for AI is writing logs

https://newsletter.vickiboykis.com/archive/my-favorite-use-case-for-ai-is-writing-logs/
232•todsacerdoti•15h ago•161 comments