Sunday, June 28, 2015
It's rather simple, but you would never know it
Rob Landley is right—terminal control is obsolete. Precious few have actual terminals, and those of us who still use command line interfaces are using software programs that emulate physical devices talking to other software programs that emulate physical devices. Furthermore, all those software programs emulating physical devices have pretty much converged on using ANSI terminal control codes, so much of the reason for termcap has gone away.
So now it should be a simple matter to look up ANSI terminal control codes to see what to send to scroll the screen to the left, right?
Yeah …
And lest you think that page on xterm
control codes is intentionally incomprehensible,
it's not.
Well,
it is incomprehensible,
and it may be intentional,
bit it's not alone.
They
are all
pretty abysmal.
And they're all pretty abysmal because the actual standard,
ECMA-48,
is pretty abysmal as standards go.
Here's a representative sample:
5.3 Elements of the C1 set
These control functions are represented
a) in a 7-bit code by 2-character escape sequences of the form ESC Fe, where ESC is represented by bit combination 01/11 and Fe is represented by a bit combination from 04/00 to 05/15;
b) in an 8-bit code by bit combinations from 08/00 to 09/15; however, when the announcer sequence ESC 02/00 04/06 according to Standard ECMA-35 is used, the control functions of the C1 set are represented by ESC Fe sequences as in a 7-bit code.
and here's a translation into more modern terminology:
5.3 Elements of the extended ASCII control set
These control functions are represented
a) in a 7-bit code by a 2-character escape sequence of the form <ESC> <Fe>, where <ESC> is ASCII character 0x1B and <Fe> is ASCII characters 0x40 ('@') through 0x5F ('_');
b) in an 8-bit code by byte values between 0x80 and 0x9F; however, when the sequence <ESC> ‘ ’ ‘F’ (0x1B 0x20 0x46) according to Standard ECMA-35 is used, the control functions of the C1 set are represented by <ESC> <Fe> sequences as in a 7-bit code.
Yes, the ECMA standards represent characters using a (to me) bizarre column-based format which are kind of hexadecimalesque (4/13 is column 4, row 13) without being actual hexadecimal (0x4D), which makes reading the standard a bit more difficult. It was only reading these old standards in conjunction with this page did is start making a bit of sense.
For instance,
on the
xterm
reference page,
there's the sequence “APC
Pt ST
” but it's never defined what APC
or ST
actually are,
but Pt is defined to be `printable text.”
It's only by reading the other documentation closely that you realize that the sequence will either be
0x9F
<printable text>0x9C
or
0x1B
‘_’ <printable text>0x1B
‘\’
Which is beside the point,
because xterm
will ignore such sequences anyway.
Sigh.
The sequences themselves are pretty simple; it's just the presentation that universally sucks (and all the presentations except the ECMA-48 one assume you have read and understand the ECMA-48 standard).