ansi_terminal/ansi_codes.h

529 lines
15 KiB
C

#ifndef ANSI_CODES_H
#define ANSI_CODES_H
/*
The standards deal with both 7-bit and 8-bit code sets. The code sets are
divided into rows and columns to form tables; the least-significant nybble
(4-bits) determines the row, while the remaining bits determine the column. A
7-bit set therefore has columns 0-7, while an 8-bit set has columns 0-15.
Codes are either control codes or graphic codes, and their meaning is either
fixed or coded according to a changeable set.
Control codes are always found in two-column sets, called C0 or primary, and C1
or supplementary. C0 is in columns 00 and 01, while C1 is found in columns 08
and 09. C0 always contains a special code ESCAPE at 01/11. C1 is only available
in 8-bit code sets. The controls coded by C1 can also be invoked in a 7-bit code
set via Escape Sequence; these use the Fe columns 04 and 05 to represent the
same controls as those in C1.
Graphic codes are in 6-column sets, called G0-G3. They are either 96-character
sets or 94-character sets. The 94-character variety don't have a code in the
first row of the first column or the last row of the last column. Those
positions correspond to SPACE and DELETE, which are fixed graphic codes, when
mapped to the left graphic set. G0 always contains a 94-character set and always
maps to columns 02-07, while G1-G3 can map either to that location (in which
case they must also contain 94-character sets) or to columns 10-15, in which
case they may be either 94-character or 96-character sets.
Control and graphic code tables are mapped into the code space into two control
code tables, CL and CR; and two graphics code tables, GL and GR.
For 8-bit codes:
CL corresponds to columns 00-01
GL corresponds to columns 02-07
CR corresponds to columns 08-09
GR corresponds to columns 10-15
CL is a C0 set and CR may contain a C1 set or be unused. GL is either a
combination of SPACE, DELETE, and a 94-character graphic set; or a 96-character
graphics set. GR is either a 94-character graphic set or a 96-character graphic
set. If more than two of G0-G3 are included, shift controls are provided to
select the ones not mapped to GL or GR. If more than two control tables or four
graphics tables are required, designation functions will be included in the code
set to re-map C0-C1, G0-G3.
For 7-bit codes:
CL corresponds to columns 00-01
GL corresponds to columns 02-07
CL contains a C0 set and GL contains either a combination of SPACE, DELETE, and
a 94-character set; or a 96-character set. It will define at least a C0 and G0
element, and may use some or all of C1 and G1-3. If more than one of G0-G3 are
included, shift functions will be included to select between them. If more than
two control tables and/or more than four graphic tables are needed, designation
functions will be included in the code set to map them to C0-C1, G0-G3.
Escape Sequences:
Escape sequences are the coded representation of code-identification functions.
Their structure is as follows:
ESCAPE <Intermediate Byte>* <Final Byte>
That is, they start with the ESCAPE byte, followed by 0 or more Intermediate
Bytes, and end with a Final Byte.
Intermediate Byte values are drawn from column 02 of the code table; they are
denoted by I.
Final Byte values are drawn from columns 03-07 excluding 07/15; they are denoted
by F.
The type of escape sequence is determined by the column number of the first byte
following ESCAPE:
02 - Type nF - Various; n is row number, see nF table
03 - Type Fp - Private Control Functions
04 & 05 - Type Fe - Control Function in C1
06 & 07 - Type Fs - Standardized Single Control Function
nF varieties:
0F : N : ANNOUNCE CODE STRUCTURE
1F : O(R) : C0-DESIGNATE
2F : O(R) : C1-DESIGNATE
3F : O(R) : Single Control Functions
4F : Y(S) : Designation of multi-byte graphic character sets
5F : O(R,S) : DESIGNATE OTHER CODING SYSTEM
6F : N : IDENTIFY REVISED REGISTRATION
7F : N : Reserved for future standardization
8F : O(R,S) : G0-DESIGNATE 94-SET
9F : O(R,S) : G1-DESIGNATE 94-SET
10F: O(R,S) : G2-DESIGNATE 94-SET
11F: O(R,S) : G3-DESIGNATE 94-SET
12F: N : Reserved for future standardization
13F: O(R,S) : G1-DESIGNATE 96-SET
14F: O(R,S) : G2-DESIGNATE 96-SET
15F: O(R,S) : G3-DESIGNATE 96-SET
N = No additional bytes
O = Optional 2nd and further bytes
Y = 2nd I byte must be present
R = Registration procedures may use 02/01-02/3 I byte to supplement the bit
combinations available to F. Additional 02-column bytes may be used as well.
S = Standardized meanings are assigned
4F 2nd-I Byte Functions:
02/08 : G0-DESIGNATE MULTIBYTE 94-SET
02/09 : G0-DESIGNATE MULTIBYTE 94-SET
02/10 : G0-DESIGNATE MULTIBYTE 94-SET
02/11 : G0-DESIGNATE MULTIBYTE 94-SET
02/12 : G0-DESIGNATE MULTIBYTE 94-SET
02/13 : G0-DESIGNATE MULTIBYTE 94-SET
02/14 : G0-DESIGNATE MULTIBYTE 94-SET
Meaning of F byte column in nF sequences:
00-02 : : Not used
03 : Fp : Reserved for Private Use
04-07 : Ft : Standardized Purposes
I.e. 3Fp indicates a private single control function, ESC 02/03 I? 03/xx
*/
enum ansi_c0 {
NUL,
SOH,
STX,
ETX,
EOT,
ENQ,
ACK,
BEL,
BS,
HT,
LF,
VT,
FF,
CR,
LS1,
LS0,
DLE,
DC1,
DC2,
DC3,
DC4,
NAK,
SYN,
ETB,
CAN,
EM,
SUB,
ESC,
IS4,
IS3,
IS2,
IS1
};
enum ansi_c1 {
//--
//--
BPH = 0x82,
NBH,
IND,
NEL,
SSA,
ESA,
HTS,
HTJ,
VTS,
PLD,
PLU,
RI,
SS2,
SS3,
DCS,
PU1,
PU2,
STS,
CCH,
MW,
SPA,
EPA,
SOS,
//--
SCI = 0x9A,
CSI,
ST,
OSC,
PM,
APC
};
/* ECMA-48 Code
C0 and C1 Functions
===================
C0 element codes C1 element codes
Column Column
Row 00 01 Row 04/08 05/09
----------------- -----------------
00 NUL DLE 00 -- DCS
01 SOH DC1 01 -- PU1
02 STX DC2 02 BPH PU2
03 ETX DC3 03 NBH STS
04 EOT DC4 04 -- CCH
05 ENQ NAK 05 NEL MW
06 ACK SYN 06 SSA SPA
07 BEL ETB 07 ESA EPA
08 BS CAN 08 HTS SOS
09 HT EM 09 HTJ --
10 LF SUB 10 VTS SCI
11 VT ESC 11 PLD CSI
12 FF IS4 12 PLU ST
13 CR IS3 13 RI OSC
14 SO/LS1 IS2 14 SS2 PM
15 SI/LS0 IS1 15 SS3 APC
Control sequences
=================
Control Sequence interpretation:
<P> = Parameter byte, drawn from col 03
<I> = Intermediate byte, drawn from col 02
<F> = Final byte, drawn from cols 04-07, col 07 is private
CSI <P>* <I>* <F>
Control sequences by F:
Column (No I) Column (I=02/00)
Row 04 05 06 04 05 06
-------------------------------------------------
00 ICH DCH HPA SL PPA TATE
01 CUU SEE HPR SR PPR TALE
02 CUD CPR REP GSM PPB TAC
03 CUF SU DA GSS SPD TCC
04 CUB SD VPA FNT DTA TSR
05 CNL NP VPR TSS SHL SCO
06 CPL PP HVP JFY SLL SRCS
07 CHA CTC TBC SPI FNK SCS
08 CUP ECH SM QUAD SPQR SLS
09 CHT CVT MC SSU SEF --
10 ED CBT HPB PFS PEC --
11 EL SRS VPB SHS SSW SCP
12 IL PTX RM SVS SACS --
13 DL SDS SGR IGS SAPV --
14 EF SIMD DSR -- STAB --
15 EA -- DAQ IDCS GCC --
Parameter interpretation:
First byte of <P>* is in 03/00-03/11:
<Param String> = <Substring List>
<Substring List> = <Substring> | <Substring> SEP <Substring List>
<Substring> = (<Digit>|DIGIT_SEP)+ | <EMPTY>
<Digit> = ZERO | ONE | TWO | THREE | FOUR | FIVE | SIX | SEVEN | EIGHT | NINE
SEP = byte 03/11
DIGIT_SEP = byte 03/10
ZERO - NINE = bytes 03/00 - 03/09
First byte of <P>* is in 03/12-03/15:
Format and meaning are privately-defined
*/
enum ansi_csi_noI {
ICH = 0x40,
CUU,
CUD,
CUF,
CUB,
CNL,
CPL,
CHA,
CUP,
CHT,
ED,
EL,
IL,
DL,
EF,
EA,
DCH,
SEE,
CPR,
SU,
SD,
NP,
PP,
CTC,
ECH,
CVT,
CBT,
SRS,
PTX,
SDS,
SIMD,
//
HPA = 0x60,
HPR,
REP,
DA,
VPA,
VPR,
HVP,
TBC,
SM,
MC,
HPB,
VPB,
RM,
SGR,
DSR,
DAQ
};
/*
Independent Control Functions
=============================
Represented by escape sequences of the form ESC Fs
Independent Control Functions by Fs
Column
Row 06 07
-----------------
00 DMI --
01 INT --
02 EMI --
03 RIS --
04 CMD --
05 -- --
06 -- --
07 -- --
08 -- --
09 -- --
10 -- --
11 -- --
12 -- LS3R
13 -- LS2R
14 LS2 LS1R
15 LS3 --
Control Strings
===============
Control string format:
<Control String> = <Opening Delim> (<Command String> | <Character String>) ST
<Opening Delim> = APC | DCS | OSC | PM | SOS
<Command String> = ((byte range 00/08 - 00/13) | (byte range 02/00 - 07/14))+
<Character String> = (any byte but SOS or ST)+
Interpretation is up to the sender/recipient of the data.
Modes
=====
Private modes can be used, but the following are standardized:
BDSM : BI-DIRECTIONAL SUPPORT MODE
EXPLICIT - Control functions performed in data or presentation component depending
on the the setting of DEVICE COMPONENT SELECT MODE
IMPLICIT - Control functions are performed in the data component.
CRM : CONTROL REPRESENTATION MODE
CONTROL - Control functions performed as defined; formator functions processed as
determined by FORMAT EFFECTOR ACTION MODE.
GRAPHIC - Control functions (except for RESET MODE) are treated as graphic
characters; device may also perform some control functions.
DCSM : DEVICE COMPONENT SELECT MODE
PRESENTATION - Control functions sensitive to this are performed in the presentation
component.
DATA - Control functions senstive to this are performed in the data component.
ERM : ERASURE MODE
PROTECT - Only contents of unprotected areas are affected by an erasure function.
ALL - All content areas are affected by an erasure function.
FEAM : FORMAT EFFECTOR ACTION MODE
EXECUTE - Format functions are performed immediately; may also be stored
STORE - Format functions are stored but not performed
FETM : FORMAT EFFECTOR TRANSFER MODE
INSERT - Format functions may be inserted into data stream to be transmitted
EXCLUDE - No format functions other than those while FEAM is set to STORE are
transmitted
GATM : GUARDED AREA TRANSFER MODE
GUARD - Only the contents of unguarded areas in an eligible area are transmitted
ALL - All contents of eligible areas are transmitted regardless of guard status
GRCM : GRAPHIC RENDITION COMBINATION MODE
REPLACING - each SELECT GRAPHICS RENDITION cancels effects of previous invocations
CUMULATIVE - each SGR changes only those effects specified, others remain
HEM : CHARACTER EDITING MODE
FOLLOWING - Insertion shifts following characters
PRECEDING - Insertion shifts preceding characters
IRM : INSERTION REPLACEMENT MODE
REPLACE - Graphic symbol replaces the one at the current display position
INSERT - Graphic symbol is inserted at the current display position
KAM : KEYBOARD ACTION MODE
ENABLED - All or part of manual input facilities are enabled
DISABLED - All or part of manual input facilities are disabled
MATM : MULTIPLE AREA TRANSFER MODE
SINGLE - Only the contents of the selected area that contains the active position
MULTIPLE - All selected areas are eliglble
PUM : POSITIONING UNIT MODE (Deprecated)
CHARACTER - The positioning unit for parameters is one character
SIZE - The positioning unit for parameters is set by SELECT SIZE UNIT
SATM : SELECTED AREA TRANSFER MODE
SELECT - Only selected areas are eligible for transfer
ALL - All areas are eligible for transfer
SRM : SEND/RECEIVE MODE
MONITOR - Data locally-entered are immediately imaged (local echo on)
SIMULTANEOUS - Only data sent to device are imaged (local echo off)
SRTM : STATUS REPORT TRANSFER MODE
NORMAL - Status reports in DEVICE CONTROL STRINGs not generated automatically
DIAGNOSTIC - Status reports in DEVICE CONTROL STRINGs included in every data stream
TSM : TABULATION STOP MODE
MULTIPLE - Tab stops are set/cleared in all lines at the same time
SINGLE - Tab stops are set/cleared only in active line
TTM : TRANSFER TERMINATION MODE
CURSOR - Contents only up to cursor are eligible for transfer
ALL - Contents before, at, and after the cursor are eligible for transfer
VEM : LINE EDITING MODE
FOLLOWING - Inserting/Deleting lines shifts following lines
PRECEDING - Inserting/Deleting lines shifts preceding lines
ZDM : ZERO DEFAULT MODE (Deprecated)
ZERO - A zero parameter to a control string means zero
DEFAULT - A zero parameter to a control string means default value
Control Functions
=================
Delimiters:
Acronym Notation Name
-----------------------------------------------
APC C1 APPLICATION PROGRAM COMMAND
CMD Fs CODING METHOD DELIMITER
DCS C1 DEVICE CONTROL STRING
OSC C1 OPERATING SYSTEM COMMAND
PM C1 PRIVACY MESSAGE
SOS C1 START OF STRING
ST C1 STRING TERMINATOR
Introducers:
Acronym Notation Name
-----------------------------------------------
CSI C1 CONTROL SEQUENCE INTRODUCER
ESC C0 ESCAPE
SCI C1 SINGLE CHARACTER INTRODUCER
Shift Functions:
Acronym Notation Name
-----------------------------------------------
LS0 C0 LOCKING-SHIFT ZERO
LS1 C0 LOCKING-SHIFT ONE
LS1R Fs LOCKING-SHIFT ONE RIGHT
LS2 Fs LOCKING-SHIFT TWO
LS2R Fs LOCKING-SHIFT TWO RIGHT
LS3 Fs LOCKING-SHIFT THREE
LS3R Fs LOCKING-SHIFT THREE RIGHT
SI C0 SHIFT-IN
SO C0 SHIFT-OUT
SS2 C1 SINGLE-SHIFT TWO
SS3 C1 SINGLE-SHIFT THREE
Format Effectors:
Acronym Notation Name
-----------------------------------------------
BS C0 BACKSPACE
CR C0 CARRIAGE RETURN
FF C0 FORM FEED
HPA Pn CHARACTER POSITION ABSOLUTE
HPB Pn CHARACTER POSITION BACKWARD
HPR Pn CHARACTER POSITION FORWARD
HT C0 CHARACTER TABULATION
HTJ C1 CHARACTER TABULATION WITH JUSTIFICATION
HTS C1 CHARACTER TABULATION SET
HVP Pn1;Pn2 CHARACTER AND LINE POSITION
LF C0 LINE FEED
NEL C1 NEXT LINE
PLD C1 PARTIAL LINE FORWARD
PLU C1 PARTIAL LINE BACKWARD
PPA Pn PAGE POSITION ABSOLUTE
PPB Pn PAGE POSITION BACKWARD
PPR Pn PAGE POSITION FORWARD
RI C1 REVERSE LINE FEED
TBC Ps TABULATION CLEAR
TSR Pn TABULATION STOP REMOVE
VPA Pn LINE POSITION ABSOLUTE
*/
#endif