1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ControlCode {
Null,
StartOfHeading,
StartOfText,
EndOfText,
EndOfTransmission,
Enquiry,
Acknowledge,
Bell,
Backspace,
HorizontalTabulation,
LineFeed,
VerticalTabulation,
FormFeed,
CarriageReturn,
ShiftOut,
ShiftIn,
DataLinkEscape,
DeviceControl1,
DeviceControl2,
DeviceControl3,
DeviceControl4,
NegativeAcknowledge,
SynchronousIdle,
EndOfTransmissionBlock,
Cancel,
EndOfMedium,
Substitute,
Escape,
FileSeparator,
GroupSeparator,
RecordSeparator,
UnitSeparator,
Space,
Delete,
}
impl ControlCode {
pub const NUL: ControlCode = ControlCode::Null;
pub const SOH: ControlCode = ControlCode::StartOfHeading;
pub const STX: ControlCode = ControlCode::StartOfText;
pub const ETX: ControlCode = ControlCode::EndOfText;
pub const EOT: ControlCode = ControlCode::EndOfTransmission;
pub const ENQ: ControlCode = ControlCode::Enquiry;
pub const ACK: ControlCode = ControlCode::Acknowledge;
pub const BEL: ControlCode = ControlCode::Bell;
pub const BS: ControlCode = ControlCode::Backspace;
pub const HT: ControlCode = ControlCode::HorizontalTabulation;
pub const LF: ControlCode = ControlCode::LineFeed;
pub const VT: ControlCode = ControlCode::VerticalTabulation;
pub const FF: ControlCode = ControlCode::FormFeed;
pub const CR: ControlCode = ControlCode::CarriageReturn;
pub const SO: ControlCode = ControlCode::ShiftOut;
pub const SI: ControlCode = ControlCode::ShiftIn;
pub const DLE: ControlCode = ControlCode::DataLinkEscape;
pub const DC1: ControlCode = ControlCode::DeviceControl1;
pub const DC2: ControlCode = ControlCode::DeviceControl2;
pub const DC3: ControlCode = ControlCode::DeviceControl3;
pub const DC4: ControlCode = ControlCode::DeviceControl4;
pub const NAK: ControlCode = ControlCode::NegativeAcknowledge;
pub const SYN: ControlCode = ControlCode::SynchronousIdle;
pub const ETB: ControlCode = ControlCode::EndOfTransmissionBlock;
pub const CAN: ControlCode = ControlCode::Cancel;
pub const EM: ControlCode = ControlCode::EndOfMedium;
pub const SUB: ControlCode = ControlCode::Substitute;
pub const ESC: ControlCode = ControlCode::Escape;
pub const FS: ControlCode = ControlCode::FileSeparator;
pub const GS: ControlCode = ControlCode::GroupSeparator;
pub const RS: ControlCode = ControlCode::RecordSeparator;
pub const US: ControlCode = ControlCode::UnitSeparator;
pub const SP: ControlCode = ControlCode::Space;
pub const DEL: ControlCode = ControlCode::Delete;
}
impl From<ControlCode> for u8 {
fn from(val: ControlCode) -> Self {
match val {
ControlCode::Null => 0,
ControlCode::StartOfHeading => 1,
ControlCode::StartOfText => 2,
ControlCode::EndOfText => 3,
ControlCode::EndOfTransmission => 4,
ControlCode::Enquiry => 5,
ControlCode::Acknowledge => 6,
ControlCode::Bell => 7,
ControlCode::Backspace => 8,
ControlCode::HorizontalTabulation => 9,
ControlCode::LineFeed => 10,
ControlCode::VerticalTabulation => 11,
ControlCode::FormFeed => 12,
ControlCode::CarriageReturn => 13,
ControlCode::ShiftOut => 14,
ControlCode::ShiftIn => 15,
ControlCode::DataLinkEscape => 16,
ControlCode::DeviceControl1 => 17,
ControlCode::DeviceControl2 => 18,
ControlCode::DeviceControl3 => 19,
ControlCode::DeviceControl4 => 20,
ControlCode::NegativeAcknowledge => 21,
ControlCode::SynchronousIdle => 22,
ControlCode::EndOfTransmissionBlock => 23,
ControlCode::Cancel => 24,
ControlCode::EndOfMedium => 25,
ControlCode::Substitute => 26,
ControlCode::Escape => 27,
ControlCode::FileSeparator => 28,
ControlCode::GroupSeparator => 29,
ControlCode::RecordSeparator => 30,
ControlCode::UnitSeparator => 31,
ControlCode::Space => 32,
ControlCode::Delete => 127,
}
}
}
impl AsRef<str> for ControlCode {
fn as_ref(&self) -> &str {
match self {
Self::Null => "^@",
Self::StartOfHeading => "^A",
Self::StartOfText => "^B",
Self::EndOfText => "^C",
Self::EndOfTransmission => "^D",
Self::Enquiry => "^E",
Self::Acknowledge => "^F",
Self::Bell => "^G",
Self::Backspace => "^H",
Self::HorizontalTabulation => "^I",
Self::LineFeed => "^J",
Self::VerticalTabulation => "^K",
Self::FormFeed => "^L",
Self::CarriageReturn => "^M",
Self::ShiftOut => "^N",
Self::ShiftIn => "^O",
Self::DataLinkEscape => "^P",
Self::DeviceControl1 => "^Q",
Self::DeviceControl2 => "^R",
Self::DeviceControl3 => "^S",
Self::DeviceControl4 => "^T",
Self::NegativeAcknowledge => "^U",
Self::SynchronousIdle => "^V",
Self::EndOfTransmissionBlock => "^W",
Self::Cancel => "^X",
Self::EndOfMedium => "^Y",
Self::Substitute => "^Z",
Self::Escape => "^[",
Self::FileSeparator => "^\\",
Self::GroupSeparator => "^]",
Self::RecordSeparator => "^^",
Self::UnitSeparator => "^_",
Self::Space => " ",
Self::Delete => "^?",
}
}
}