TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

ANSI escape codes (2019)

145 pointsby brendanfalkover 4 years ago

20 comments

blueflowover 4 years ago
The article nor the comment section mention curses or the terminfo database, which makes me sad.<p>Wanna read something about terminals and terminal control sequences? <a href="https:&#x2F;&#x2F;invisible-island.net&#x2F;ncurses&#x2F;terminfo.src.html" rel="nofollow">https:&#x2F;&#x2F;invisible-island.net&#x2F;ncurses&#x2F;terminfo.src.html</a><p>Disclaimer: i use a DEC VT520
评论 #26013384 未加载
评论 #26013411 未加载
评论 #26013010 未加载
评论 #26013556 未加载
评论 #26016547 未加载
rootw0rmover 4 years ago
Back in the 90s I played a MUD called Ancient Anguish. It&#x27;s the type of MUD where inventory is dropped on logout. I learned they didn&#x27;t filter for control sequences, and so I would rewrite the text on screen to do all sorts of nefarious things, like make people think they were ambushed and almost dead (thus possibly trying to quit to save EXP loss). I could also forge tells&#x2F;yells to make them look like they came from someone else. It was funny to me at the time, lol.<p>edit: for fun i just checked out it&#x27;s current status and it&#x27;s still around, awesome. and rule #4 is now don&#x27;t abuse control codes. hahaha, sorry guys. AFAIK they started filtering them soon after me and a cohort caused some chaos.
albertzeyerover 4 years ago
There is much more, though.<p>See here for an overview:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;albertz&#x2F;wiki&#x2F;blob&#x2F;master&#x2F;terminal-escape-codes.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;albertz&#x2F;wiki&#x2F;blob&#x2F;master&#x2F;terminal-escape-...</a><p>There are a couple of non-standard extensions, e.g. by iTerm:<p><a href="https:&#x2F;&#x2F;iterm2.com&#x2F;documentation-escape-codes.html" rel="nofollow">https:&#x2F;&#x2F;iterm2.com&#x2F;documentation-escape-codes.html</a> <a href="https:&#x2F;&#x2F;iterm2.com&#x2F;documentation-images.html" rel="nofollow">https:&#x2F;&#x2F;iterm2.com&#x2F;documentation-images.html</a><p>Some of them are pretty complicated to standardize. E.g. see this discussion on simple image support:<p><a href="https:&#x2F;&#x2F;gitlab.freedesktop.org&#x2F;terminal-wg&#x2F;specifications&#x2F;-&#x2F;issues&#x2F;12" rel="nofollow">https:&#x2F;&#x2F;gitlab.freedesktop.org&#x2F;terminal-wg&#x2F;specifications&#x2F;-&#x2F;...</a>
评论 #26014960 未加载
eqvinoxover 4 years ago
On a Linux box, you can also just do<p><pre><code> man console_codes </code></pre> which is significantly more extensive than the posted link
评论 #26013502 未加载
评论 #26015023 未加载
masukomiover 4 years ago
To the 4 of you who actually care enough about this information to write something with it I offer you the following blatant self promotion:<p>oho <a href="https:&#x2F;&#x2F;github.com&#x2F;masukomi&#x2F;oho" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;masukomi&#x2F;oho</a> is the best ASNI-&gt;HTML converter out there.<p>useful if you want to take your colorful terminal output and share it on a web page, OR if you&#x27;re really geeky you can write CLI tools with colored output, to summarize data then convert it to HTML, then to PDF and share it with your coworkers. (Chrome&#x27;s command line interface is the best HTML to PDF converter I&#x27;ve found).
epistemexover 4 years ago
&gt; The majority of these escape codes start with \x1b[<p>This is actually the 7-bit version for CSI. A less known variation is the 8-bit CSI which is simply \x9b and is the same as \x1b[ combined. So, for example \x9b33m does the same as \x1b[33m .<p>Unfortunately, there exist a couple of (8-bit) terminals that don&#x27;t support this version.
watersbover 4 years ago
I was playing with vttest today. Odd terminal emulator features.<p>Vttest: <a href="https:&#x2F;&#x2F;invisible-island.net&#x2F;vttest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;invisible-island.net&#x2F;vttest&#x2F;</a>
评论 #26013433 未加载
评论 #26014686 未加载
评论 #26012458 未加载
评论 #26012806 未加载
billpgover 4 years ago
Blatant plug: That time I accidentally discovered my text terminal had a graphics mode.<p><a href="https:&#x2F;&#x2F;hackensplat.com&#x2F;falco-t310-unleashed&#x2F;" rel="nofollow">https:&#x2F;&#x2F;hackensplat.com&#x2F;falco-t310-unleashed&#x2F;</a>
评论 #26012427 未加载
dejjover 4 years ago
&gt; colours are ordered by usefulness<p>And then I finally realized they’re RGB vectors and additive:<p>000: black<p>001: red<p>010: green<p>011: yellow<p>100: blue<p>101: magenta<p>110: cyan<p>111: white
评论 #26015700 未加载
rbanffyover 4 years ago
For proper status lines, use SGR 53 for overlines.<p><a href="https:&#x2F;&#x2F;twitter.com&#x2F;0xDEADBEEFCAFE&#x2F;status&#x2F;1256285362260934656" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;0xDEADBEEFCAFE&#x2F;status&#x2F;125628536226093465...</a>
faeyanpiraatover 4 years ago
You could color code chat messages and your name in Call of Duty 2 in the following way:<p>^1Red<p>Everything after the &quot;^1&quot; were red.<p>The game removed these color codes when it showed your name, but you could do ^^11Red to bypass that (it only removed color codes for one pass)
评论 #26012554 未加载
kyberiasover 4 years ago
Seems to me it&#x27;s bad practice to combine the text you want to show with the formatting (escape codes) in string literals. Everything is then immediately dependent on specific type of UI technology (terminal).
评论 #26012543 未加载
评论 #26014204 未加载
评论 #26013063 未加载
account42over 4 years ago
&gt; 0 and 7 are less useful for text because one or the other will generally look nearly-unreadable depending on whether the user has a light or a dark background.<p>This really annoys me about the bright themes used by default in some distros - if you make the default background white instead of black then please also swap the &quot;white&quot; and &quot;black&quot; foreground colors. And make sure all the other ones are readable on the default background for that matter.
junonover 4 years ago
I&#x27;m a maintainer of chalk. I&#x27;m not the first to mention this, but this article is only really parroting the information found on the Wikipedia article for escape sequences, which in turn only really covers xterm-256color terminals.<p>To be quite honest, I feel as though terminal technology is the most antiquated thing still in wide use today. It&#x27;s slow, there are so many competing standards and none of them are really that well standardized, and the libraries needed to be truly compatible (terminfo in particular, for which I&#x27;ve written several full parsers and boy what a mess that is) are clunky, outdated and also very slow.<p>This is a hard problem to solve, however. There are more CSI sequences than just \x1b for example, though that is by far the most common these days. Not treating output as text streams would be an interesting start but that would require rewriting pretty much all software ever to exist.<p>Meh. I&#x27;ve spent too much time working with escape sequences and thinking about this problem. I am young, but I&#x27;ll probably die before TTYs do.
AnonHPover 4 years ago
Mods: This needs a 2019 in the title (not that escape sequences have been changing rapidly in the recent times :) )<p>This article was a nice and concise introduction. I wish it had linked to some canonical sources of more comprehensive information though.<p>Also, the link to the Anki flash cards doesn’t work now.
112233over 4 years ago
recommended reading:<p><pre><code> - vt100.net - xterm control sequences - ECMA-48 </code></pre> Note that CSI is actually part of C1 set, code 0x9B, (sent bytes depend on used encding).<p>Be avare that it is completely valid to have control characters such as carriage return in the middle of control sequence.
评论 #26013851 未加载
rramadassover 4 years ago
This brings back memories. In the beginning of my career (early 90&#x27;s) i implemented an entire UI for a Personnel Information System in COBOL on a Mainframe (CDC Cyber 180&#x2F;840A) using ANSI escape sequences.<p>Please don&#x27;t judge me :-)
评论 #26023970 未加载
tdaover 4 years ago
After reading this, I can confirm the title checks out
评论 #26012130 未加载
drummerover 4 years ago
This is very nicely explained in terms of calling functions. It all makes much more sense now.
aidenn0over 4 years ago
iso-8859-1 (and by extension UTF-8) specify a single-character CSI. Does anyone know if any terminals will accept this?
评论 #26019575 未加载