ansi_control_codes/c0.rs
1//! Elements of the C0 set.
2//!
3//! These control functions are represented in 7-bit codes by bit combinations from `00/00` to `01/15`.
4//!
5//! The 3-character escape sequence designating and invoking this C0 set is `ESC 02/01 04/00`,
6//! see [`ANNOUNCER_SEQUENCE`].
7//!
8//! It is assumed that even with no invoked C0 set, the control character `ESCAPE` ([`ESC`]) is always available, and is
9//! represented by bit combination `01/11`.
10//!
11//! ## Usage
12//!
13//! You can use the Elements of the C0 set inside normal strings, format them with the `format!()` macro, or print
14//! them with the `print!()` and `println!()` macros.
15//!
16//! For example, designate the C0 set, then ring the bell.
17//!
18//! ```
19//! use ansi_control_codes::c0::{ANNOUNCER_SEQUENCE, BEL};
20//! println!("{}{}", ANNOUNCER_SEQUENCE, BEL);
21//! ```
22//!
23//! ## Overview of the C0 Set
24//!
25//! | Row Number | Column `00` | Column `01` |
26//! | ---------: | :---------: | :---------: |
27//! | `00` | [`NUL`] | [`DLE`] |
28//! | `01` | [`SOH`] | [`DC1`] |
29//! | `02` | [`STX`] | [`DC2`] |
30//! | `03` | [`ETX`] | [`DC3`] |
31//! | `04` | [`EOT`] | [`DC4`] |
32//! | `05` | [`ENQ`] | [`NAK`] |
33//! | `06` | [`ACK`] | [`SYN`] |
34//! | `07` | [`BEL`] | [`ETB`] |
35//! | `08` | [`BS`] | [`CAN`] |
36//! | `09` | [`HT`] | [`EM`] |
37//! | `10` | [`LF`] | [`SUB`] |
38//! | `11` | [`VT`] | [`ESC`] |
39//! | `12` | [`FF`] | [`IS4`] |
40//! | `13` | [`CR`] | [`IS3`] |
41//! | `14` | [`SO`] | [`IS2`] |
42//! | `15` | [`SI`] | [`IS1`] |
43use crate::ControlFunction;
44
45macro_rules! c0 {
46 ($xx:literal/$yy:literal) => {
47 ControlFunction::new_c0(ascii!($xx / $yy))
48 };
49}
50
51/// Announcer Sequence for Control Set C0.
52///
53/// Designate the C0 set of control functions as the active set of control functions.
54///
55/// ## Note 1
56///
57/// The use of this escape sequence implies that all control function of this C0 set must be implemented.
58///
59/// ## Note 2
60///
61/// It is assumed that even with no invoked C0 set, the control character ESCAPE (`ESC`) is available, and is
62/// represented by the bit combination `01/11`.
63pub const ANNOUNCER_SEQUENCE: &str = ascii!(01 / 11, 02 / 01, 04 / 00);
64
65/// Acknowledge.
66///
67/// `ACK` is transmitted by a receiver as an affirmative response to the sender.
68///
69/// The use of `ACK` is defined in [ISO 1745][iso-1745].
70///
71/// [iso-1745]: https://www.ecma-international.org/wp-content/uploads/ECMA-16_2nd_edition_june_1973.pdf
72pub const ACK: ControlFunction = c0!(00 / 06);
73
74/// Bell.
75///
76/// `BEL` is used when there is a need to call for attention; it may control alarm or attention devices.
77pub const BEL: ControlFunction = c0!(00 / 07);
78
79/// Backspace.
80///
81/// `BS` causes the active data position to be moved one character position in the data component in the direction
82/// opposite to that of the implicit movement.
83///
84/// The direction of the implicit movement depends on the parameter value of Select Implicit Movement Direction
85/// ([`SIMD`][crate::control_sequences::SIMD]).
86pub const BS: ControlFunction = c0!(00 / 08);
87
88/// Cancel.
89///
90/// `CAN` is used to indicate that the data preceding it in the data stream is in error. As a result, this data shall be
91/// ignored. The specific meaning of this control function shall be defined for each application and/or between sender
92/// and recipient.
93pub const CAN: ControlFunction = c0!(01 / 08);
94
95/// Carriage Return.
96///
97/// The effect of `CR` depends on the setting of the DEVICE COMPONENT SELECT MODE ([`DCSM`][crate::modes::DCSM]) and
98/// on the parameter value of SELECT IMPLICIT MOVEMENT DIRECTION ([`SIMD`][crate::control_sequences::SIMD]).
99///
100/// If the DEVICE COMPONENT SELECT MODE ([`DCSM`][crate::modes::DCSM]) is set to PRESENTATION and with the parameter
101/// value of [`SIMD`][crate::control_sequences::SIMD] equal to
102/// [`Normal`][crate::control_sequences::MovementDirection::Normal], `CR` causes the active presentation position to be
103/// moved to the line home position of the same line in the presentation component. The line home position is
104/// established by the parameter value of SET LINE HOME ([`SLH`][crate::control_sequences::SLH]).
105///
106/// With a parameter value of [`SIMD`][crate::control_sequences::SIMD] equal to
107/// [`Opposite`][crate::control_sequences::MovementDirection::Opposite], `CR` causes the active presentation position to
108/// be moved to the line limit position of the same line in the presentation component. The line limit position is
109/// established by the parameter value of SET LINE LIMIT ([`SLL`][crate::control_sequences::SLL]).
110///
111/// If the DEVICE COMPONENT SELECT MODE ([`DCSM`][crate::modes::DCSM]) is set to DATA and with a parameter of
112/// [`SIMD`][crate::control_sequences::SIMD] equal to [`Normal`][crate::control_sequences::MovementDirection::Normal],
113/// `CR` causes the active data position to be moved to the line home position of the same line in the data component.
114/// The line home position is established by the parameter value of SET LINE HOME
115/// ([`SLH`][crate::control_sequences::SLH]).
116///
117/// With a parameter value of [`SIMD`][crate::control_sequences::SIMD] equal to
118/// [`Opposite`][crate::control_sequences::MovementDirection::Opposite], `CR` causes the active data position to be
119/// moved to the line limit position of the same line in the data component. The line limit position is established by
120/// the parameter value of SET LINE LIMIT ([`SLL`][crate::control_sequences::SLL]).
121pub const CR: ControlFunction = c0!(00 / 13);
122
123/// Device Control One.
124///
125/// `DC1` is primarily intended for tuning on or starting an ancillary device. If it is not required for this purpose,
126/// it may be used to restore a device to the basic mode of operation (see also [`DC2`] and [`DC3`]), or any other
127/// device control function not provided by other DCs.
128///
129/// ## Note
130///
131/// When used for data flow control, `DC1` is sometimes called `X-ON`.
132pub const DC1: ControlFunction = c0!(01 / 01);
133
134/// Device Control Two.
135///
136/// `DC2` is primarily intended for tuning on or starting an ancillary device. If it is not required for this purpose,
137/// it may be used to set a device to a special mode of operation (in which case [`DC1`] is used to restore the device
138/// to the basic mode), or for any other device control function not provided by other DCs.
139pub const DC2: ControlFunction = c0!(01 / 02);
140
141/// Device Control Three.
142///
143/// `DC3` is primarily intended for turning off or stopping an ancillary device. This function may be a secondary level
144/// stop, for example wait, pause, stand-by or halt (in which case [`DC1`] is used to restore normal operation). If it
145/// is not required for this purpose, it may be used for any other device control function not provided by other DCs.
146pub const DC3: ControlFunction = c0!(01 / 03);
147
148/// Device Control Four.
149///
150/// `DC4` is primarily intended for turning off, stopping or interrupting an ancillary device. If it is not required for
151/// this purpose, it may be used for any other device control function not provided by other DCs.
152pub const DC4: ControlFunction = c0!(01 / 04);
153
154/// Data Link Escape.
155///
156/// `DLE` is used exclusively to provide supplementary transmission control functions.
157///
158/// The use of `DLE` is defined in [ISO 1745][iso-1745].
159///
160/// [iso-1745]: https://www.ecma-international.org/wp-content/uploads/ECMA-16_2nd_edition_june_1973.pdf
161pub const DLE: ControlFunction = c0!(01 / 00);
162
163/// End Of Medium.
164///
165/// `EM` is used to identify the physical end of a medium, or the end of the used portion of a medium, or the end of the
166/// wanted portion of data recorded on a medium.
167pub const EM: ControlFunction = c0!(01 / 09);
168
169/// Enquiry.
170///
171/// `ENQ` is transmitted by a sender as a request for a response from a receiver.
172///
173/// The use of `ENQ` is defined in [ISO 1745][iso-1745].
174///
175/// [iso-1745]: https://www.ecma-international.org/wp-content/uploads/ECMA-16_2nd_edition_june_1973.pdf
176pub const ENQ: ControlFunction = c0!(00 / 05);
177
178/// End Of Transmission.
179///
180/// `EOT` is used to indicate the conclusion of the transmission of one or more texts.
181///
182/// The use of `EOT` is defined in [ISO 1745][iso-1745].
183///
184/// [iso-1745]: https://www.ecma-international.org/wp-content/uploads/ECMA-16_2nd_edition_june_1973.pdf
185pub const EOT: ControlFunction = c0!(00 / 04);
186
187/// Escape.
188///
189/// `ESC` is used for code extension purposes. It causes the meanings of a limited number of bit combinations following
190/// it in the data stream to be changed.
191///
192/// The use of `ESC` is defined in Standard [ECMA-35][ecma-35].
193///
194/// [ecma-35]: https://www.ecma-international.org/wp-content/uploads/ECMA-35_6th_edition_december_1994.pdf
195pub const ESC: ControlFunction = c0!(01 / 11);
196
197/// End Of Transmission Block.
198///
199/// `ETB` is used to indicate the end of a block of data where the data are divided into such blocks for transmission
200/// purposes.
201///
202/// The use of `ETB` is defined in [ISO 1745][iso-1745].
203///
204/// [iso-1745]: https://www.ecma-international.org/wp-content/uploads/ECMA-16_2nd_edition_june_1973.pdf
205pub const ETB: ControlFunction = c0!(01 / 07);
206
207/// End Of Text.
208///
209/// `ETX` is used to indicate the end of a text.
210///
211/// The use of `ETX` is defined in [ISO 1745][iso-1745].
212///
213/// [iso-1745]: https://www.ecma-international.org/wp-content/uploads/ECMA-16_2nd_edition_june_1973.pdf
214pub const ETX: ControlFunction = c0!(00 / 03);
215
216/// Form Feed.
217///
218/// `FF` causes the active presentation position to be moved to the corresponding character position of the line at the
219/// page home position of the next form or page in the presentation component. The page home position is established by
220/// the parameter value of SET PAGE HOME ([`SPH`][crate::control_sequences::SPH]).
221pub const FF: ControlFunction = c0!(00 / 12);
222
223/// Character Tabulation.
224///
225/// `HT` causes the active presentation position to be moved to the following character tabulation stop in the
226/// presentation component.
227///
228/// In addition, if that following character tabulation stop has been set by TABULATION ALIGN CENTRE
229/// ([`TAC`][crate::control_sequences::TAC]), TABULATION ALIGN LEADING EDGE ([`TALE`][crate::control_sequences::TALE]),
230/// TABULATION ALIGN TRAILING EDGE ([`TATE`][crate::control_sequences::TATE]) or TABULATION CENTRED ON CHARACTER
231/// ([`TCC`][crate::control_sequences::TCC]), `HT` indicates the beginning of a string of text which is to be positioned
232/// within a line according to the properties of that tabulation stop. The end of the string is indicated by the next
233/// occurrence of `HT` or CARRIAGE RETURN ([`CR`]) or NEXT LINE ([`NEL`][crate::c1::NEL]) in the data stream.
234pub const HT: ControlFunction = c0!(00 / 09);
235
236/// Information Separator One (US - Unit Separator).
237///
238/// `IS1` is used to separate and qualify data logically; its specific meaning has to be defined for each application.
239/// If this control function is used in hierarchical order, it may delimit a data item called a unit.
240pub const IS1: ControlFunction = c0!(01 / 15);
241
242/// Information Separator Two (RS - Record Separator).
243///
244/// `IS2` is used to separate and qualify data logically; its specific meaning has to be defined for each application.
245/// If this control function is used in hierarchical order, it may delimit a data item called a record.
246pub const IS2: ControlFunction = c0!(01 / 14);
247
248/// Information Separator Three (GS - Group Separator).
249///
250/// `IS3` is used to separate and qualify data logically; its specific meaning has to be defined for each application.
251/// If this control function is used in hierarchical order, it may delimit a data item called a group.
252pub const IS3: ControlFunction = c0!(01 / 13);
253
254/// Information Separator Four (FS - File Separator).
255///
256/// `IS4` is used to separate and qualify data logically; its specific meaning has to be defined for each application.
257/// If this control function is used in hierarchical order, it may delimit a data item called a file.
258pub const IS4: ControlFunction = c0!(01 / 12);
259
260/// Line Feed.
261///
262/// If the DEVICE COMPONENT SELECT MODE ([`DCSM`][crate::modes::DCSM]) is set to PRESENTATION, `LF` causes the active
263/// presentation position to be moved to the corresponding character position of the following line in the presentation
264/// component.
265///
266/// If the DEVICE COMPONENT SELECT MODE ([`DCSM`][crate::modes::DCSM]) is set to DATA, `LF` causes the active data
267/// position to be moved to the corresponding character position of the following line in the data component.
268pub const LF: ControlFunction = c0!(00 / 10);
269
270/// Locking-Shift Zero.
271///
272/// `LS0` is used for code extension purposes. It causes the meanings of the bit combinations following it in the data
273/// stream to be changed.
274///
275/// The use of `LS0` is defined in Standard ECMA-35.
276///
277/// ## Note
278///
279/// `LS0` is used in 8-bit environments only; in 7-bit environments SHIFT-IN ([`SI`]) is used instead.
280pub const LS0: ControlFunction = c0!(00 / 15);
281
282/// Locking-Shift One.
283///
284/// `LS1` is used for code extension purposes. It causes the meanings of the bit combinations following it in the data
285/// stream to be changed.
286///
287/// The use of `LS1` is defined in Standard [ECMA-35][ecma-35].
288///
289/// ## Note
290///
291/// `LS1` is used in 8-bit environments only; in 7-bit environments SHIFT-OUT ([`SO`]) is used instead.
292///
293/// [ecma-35]: https://www.ecma-international.org/wp-content/uploads/ECMA-35_6th_edition_december_1994.pdf
294pub const LS1: ControlFunction = c0!(00 / 14);
295
296/// Negative Acknowledge.
297///
298/// `NAK` is transmitted by a receiver as a negative response to the sender.
299///
300/// The use of `NAK` is defined in [ISO 1745][iso-1745].
301///
302/// [iso-1745]: https://www.ecma-international.org/wp-content/uploads/ECMA-16_2nd_edition_june_1973.pdf
303pub const NAK: ControlFunction = c0!(01 / 05);
304
305/// Null.
306///
307/// `NUL` is used for media-fill or time-fill. `NUL` characters may be inserted into, or removed from, a data stream
308/// without affecting information content of that stream, but such action may affect the information layout and/or the
309/// control of equipment.
310pub const NUL: ControlFunction = c0!(00 / 00);
311
312/// Shift-In.
313///
314/// `SI` is used for code extension purposes. It causes the meanings of the bit combinations following it in the data
315/// stream to be changed.
316///
317/// The use of `SI` is defined in Standard [ECMA-35][ecma-35].
318///
319/// ## Note
320///
321/// `SI` is used in 7-bit environments only; in 8-bit environments LOCKING-SHIFT ZERO ([`LS0`]) is used instead.
322///
323/// [ecma-35]: https://www.ecma-international.org/wp-content/uploads/ECMA-35_6th_edition_december_1994.pdf
324pub const SI: ControlFunction = c0!(00 / 15);
325
326/// Shift-Out.
327///
328/// `SO` is used for code extension purposes. It causes the meanings of the bit combinations following it in the data
329/// stream to be changed.
330///
331/// The use of `SI` is defined in Standard [ECMA-35][ecma-35].
332///
333/// ## Note
334///
335/// `SO` is used in 7-bit environments only; in 8-bit environments LOCKING-SHIFT ONE ([`LS1`]) is used instead.
336///
337/// [ecma-35]: https://www.ecma-international.org/wp-content/uploads/ECMA-35_6th_edition_december_1994.pdf
338pub const SO: ControlFunction = c0!(00 / 14);
339
340/// Start of Heading.
341///
342/// `SOH` is used to indicate the beginning of a heading.
343///
344/// The use of `SOH` is defined in [ISO 1745][iso-1745].
345///
346/// [iso-1745]: https://www.ecma-international.org/wp-content/uploads/ECMA-16_2nd_edition_june_1973.pdf
347pub const SOH: ControlFunction = c0!(00 / 01);
348
349/// Start of Text.
350///
351/// `STX` is used to indicate the beginning of a text and the ned of a heading.
352///
353/// The use of `STX` is defined in [ISO 1745][iso-1745].
354///
355/// [iso-1745]: https://www.ecma-international.org/wp-content/uploads/ECMA-16_2nd_edition_june_1973.pdf
356pub const STX: ControlFunction = c0!(00 / 02);
357
358/// Substitute.
359///
360/// `SUB` is used in the place of a character that has been found to be invalid or in error. `SUB` is intended to be
361/// introduced by automatic means.
362pub const SUB: ControlFunction = c0!(01 / 10);
363
364/// Synchronous Idle.
365///
366/// `SYN` is used by a synchronous transmission system in the absence of any other character (idle condition) to provide
367/// a signal from which synchronism may be achieved or retained between data terminal equipment.
368///
369/// The use of `SYN` is defined in [ISO 1745][iso-1745].
370///
371/// [iso-1745]: https://www.ecma-international.org/wp-content/uploads/ECMA-16_2nd_edition_june_1973.pdf
372pub const SYN: ControlFunction = c0!(01 / 06);
373
374/// Line Tabulation.
375///
376/// `VT` causes the active presentation position to be moved in the presentation component to the corresponding
377/// character position on the line at which the following line tabulation stop is set.
378pub const VT: ControlFunction = c0!(00 / 11);