bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to interpret ansi escape code like "\033[; 1; 31mHello World\033


From: Tim Allen
Subject: Re: How to interpret ansi escape code like "\033[; 1; 31mHello World\033[0m"?
Date: Thu, 20 Nov 2008 08:53:11 +1100
User-agent: Mutt/1.5.18 (2008-05-17)

On Wed, Nov 19, 2008 at 11:35:39PM +0800, John Daker wrote:
> My question is where should I start?
> Where can I get the whole escape code list?

If you want to write your own terminal emulator, I'd start by looking at
the official xterm control sequences list:

    http://invisible-island.net/xterm/ctlseqs/ctlseqs.html

(I believe the original version was a LaTeX document or similar that
used fancy formatting like boxes to convey information; I recall getting
rather confused reading the HTML and plain-text versions of the document
until I tracked down a PDF copy, but the HTML version should be good to
start with).

Note that the control-sequences documentation lists various features,
but doesn't mention any of the interaction corner-cases. Maybe the
ECMA-48 standard (sometimes called 'ansi') defines some of the
corner-cases, but I'll bet it doesn't mention things like double-width
characters, Unicode or resizable terminals.

When I was playing with the idea of writing a terminal emulator a while
ago, I tried various behaviours in different terminals to figure out
what I thought the 'correct' behaviour should be; I left my notes here:

    http://screwtape.jottit.com/notes_on_terminal_emulation

> Which part of the list should I interpret in my program to make sure
> 'vim','top' and so on can work properly?

Ideally, you'd implement all of it; in practice the 80/20 rule applies
and by implementing cursor movement, erasing, and colours you'd probably
get a lot of programs mostly working. Just don't configure your terminal
emulator to claim to be xterm unless it really does implement every
xterm feature.

Other things I've discovered that haven't been mentioned here yet:

    http://rote.sourceforge.net/ is a C library implementing a subset of
    VT102 control sequences; it's the only VT102 emulation code I've
    seen that can be added to other programs and (unlike libvte) doesn't
    require a particular GUI toolkit.

    http://invisible-island.net/vttest/vttest.html is a tool to test
    your terminal emulator to see how closely it emulates an actual
    terminal.

    http://vt100.net/docs/vt220-rm/contents.html is an online copy of
    the VT220 reference manual, which describes a lot of the simpler
    control sequences in more detail than the xterm doc does.

    http://invisible-island.net/luit/luit.html is a program that
    handles one of the scarier portions of VTxxx emulation: character
    sets. Instead of fork()ing and exec()ing the program you want to run
    directly, exec() luit and tell it to run the program - then you can
    ignore character-encoding issues and just read nice, clean UTF-8.
    Figuring out how eight-bit control characters and UTF-8 interact is
    an exercise for the reader.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]