Terminal – DEC ANSI Command Sequence for Cursor Movement

cursorescape-charactersterminal

So I'm writing a terminal emulation (I know, I should just compile putty, etc.) and am at the stage of plodding through vttest to make sure it's right. I'm basing it on the VT102 for now but will add later terminal features such as color when the basics are working right.

The command set is mostly ANSI. DEC had their own command set but supported the ANSI commands from about 1973. Those ANSI standards are apparently not available now but the ECMA equivalents are, I have them (ECMA-48 seems most relevant) but does not answer this question as far as I can see. Most ANSI command sequences start with ESC. Many commands start with the command sequence identifier shown here as CSI and represented in the data as 0x1c 0x5b (ESC [), or 0xdb if 8-bit communication was possible. Then followed a sequence identifying the command. Some commands affect cursor position, some the screen, some provoke a response to the host and so on.

Some terminal commands include a numeric argument. Example CSI 10 ; 5 H means make the cursor position row 10, column 5. When the numeric argument is missing there is a default value to use: CSI 10 ; H means make the cursor position row 10, column 1 because 1 is the default value when an argument is not given.

I have the vt102 manual from vt100.net (great resource) and about a dozen pages giving partial information on these command sequences. Apparently the complete gospel DEC terminal spec never made it out of DEC.

What is clear is that CSI C is move cursor right and that the default value is 1.

What isn't clear is what is the meaning of CSI 0 C.

Why have a zero there, it would seem to make the command do nothing? If it means "use default value" then it could have been sent as 1 instead, but the shorter string would have no argument and rely on the default value being interpreted as 1 anyway. These actual physical VT terminals were often used at 300 baud and below so the one character did matter!

I'm not so advanced with vttest that I can just try it both ways and see which makes everything perfect but I'm far enough that little questions like this are starting to matter.

Best Answer

I got in touch with Thomas Dickey (invisible-island.net) who maintains xterm and vttest - he explained that CSI 0 C is the same as CSI 1 C or CSI C in xterm.

For anyone looking for more information on terminal programming I highly recommend checking out the xterm source he hosts - specifically the ctlseqs.txt inside xterm, which looks very much like the one true terminal control sequences reference I've been searching for.