devela/sys/os/linux/consts/
termios.rs

1// devela::sys::os::linux::consts::termios
2//
3//! linux [`termios`] flags
4//!
5//! [`termios`]: https://man7.org/linux/man-pages/man3/termios.3.html
6//
7// - https://man7.org/linux/man-pages/man0/termios.h.0p.html
8// - https://man7.org/linux/man-pages/man1/stty.1.html
9//
10
11#![allow(non_camel_case_types, clippy::zero_prefixed_literal)]
12
13use core::ffi::c_uint;
14
15/// [`LinuxTermios`][super::super::LinuxTermios] input flags.
16pub struct LINUX_TERMIOS_IFLAG;
17
18/// [`LinuxTermios`][super::super::LinuxTermios] output flags.
19pub struct LINUX_TERMIOS_OFLAG;
20
21/// [`LinuxTermios`][super::super::LinuxTermios] control flags.
22pub struct LINUX_TERMIOS_CFLAG;
23
24/// [`LinuxTermios`][super::super::LinuxTermios] local flags.
25pub struct LINUX_TERMIOS_LFLAG;
26
27impl LINUX_TERMIOS_IFLAG {
28    /// Ignore BREAK condition on input.
29    pub const IGNBRK: c_uint = 0_000_001;
30
31    /// Signal interrupt on BREAK.
32    /// If [`IGNBRK`](Self::IGNBRK) is set, a BREAK is ignored.
33    ///
34    /// If it is not set but `BRKINT` is set, then a BREAK causes the input and
35    /// output queues to be flushed, and if the terminal is the controlling
36    /// terminal of a foreground process group, it will cause a `SIGINT` to be
37    /// sent to this foreground process group.
38    ///
39    /// When neither `IGNBRK` nor `BRKINT` are set, a BREAK reads as a null byte
40    /// ('\0'), except when [`PARMRK`](Self::PARMRK) is set, in which case it
41    /// reads as the sequence `\377` `\0` `\0`.
42    pub const BRKINT: c_uint = 0_000_002;
43
44    /// Ignore framing errors and parity errors.
45    pub const IGNPAR: c_uint = 0_000_004;
46
47    /// Mark parity and framing errors.
48    ///
49    /// If this bit is set, input bytes with parity or framing
50    /// errors are marked when passed to the program.
51    ///
52    /// This bit is meaningful only when [`INPCK`](Self::INPCK) is set and
53    /// [`IGNPAR`](Self::IGNPAR) is not set.
54    ///
55    /// The way erroneous bytes are marked is with two preceding
56    /// bytes, `\377` and `\0`.
57    ///
58    /// Thus, the program actually reads three bytes for one erroneous byte
59    /// received from the terminal.
60    ///
61    /// If a valid byte has the value `\377`, and [`ISTRIP`](Self::ISTRIP) is
62    /// not set, the program might confuse it with the prefix that marks a
63    /// parity error.
64    ///
65    /// Therefore, a valid byte `\377` is passed to the program as two bytes,
66    /// `\377` `\377`, in this case.
67    ///
68    /// If neither `IGNPAR` nor `PARMRK` is set, read a character with a parity
69    /// error or framing error as `\0`.
70    pub const PARMRK: c_uint = 0_000_010;
71
72    /// Enable input parity checking.
73    pub const INPCK: c_uint = 0_000_020;
74
75    /// Strip off eighth bit.
76    pub const ISTRIP: c_uint = 0_000_040;
77
78    /// Translate `NL` to `CR` on input.
79    pub const INLCR: c_uint = 0_000_100;
80
81    /// Ignore `CR` (carriage return) on input.
82    pub const IGNCR: c_uint = 0_000_200;
83
84    /// Translate CR to NL (carriage return to newline) on input
85    /// (unless [`IGNCR`](Self::IGNCR) is set).
86    pub const ICRNL: c_uint = 0_000_400;
87
88    /// Map uppercase characters to lowercase on input (not in POSIX).
89    pub const IUCLC: c_uint = 0_001_000;
90
91    /// Enable XON/XOFF flow control on output.
92    pub const IXON: c_uint = 0_002_000;
93
94    /// (XSI) Typing any character will restart stopped output.
95    ///
96    /// (The default is to allow just the START character to
97    /// restart output.)
98    pub const IXANY: c_uint = 0_004_000;
99
100    /// Enable XON/XOFF flow control on input.
101    pub const IXOFF: c_uint = 0_010_000;
102
103    /// Ring bell when input queue is full (not in POSIX).
104    ///
105    /// Linux does not implement this bit, and acts as if it is always set.
106    pub const IMAXBEL: c_uint = 0_020_000;
107
108    /// Input is UTF8. (not in POSIX)
109    ///
110    /// This allows character-erase to be correctly performed in cooked mode.
111    ///
112    /// (since Linux 2.6.4)
113    pub const IUTF8: c_uint = 0_040_000;
114}
115
116impl LINUX_TERMIOS_OFLAG {
117    /// Enable implementation-defined output processing.
118    pub const OPOST: c_uint = 0_000_001;
119
120    /// Map lowercase characters to uppercase on output. (not in POSIX)
121    pub const OLCUC: c_uint = 0_000_002;
122
123    /// (XSI) Map NL to CR-NL on output.
124    pub const ONLCR: c_uint = 0_000_004;
125
126    /// Map CR to NL on output.
127    pub const OCRNL: c_uint = 0_000_010;
128
129    /// Don't output CR at column 0.
130    pub const ONOCR: c_uint = 0_000_020;
131
132    /// The `NL` character is assumed to do the carriage-return
133    /// function; the kernel's idea of the current column is set
134    /// to 0 after both `NL` and `CR`.
135    pub const ONLRET: c_uint = 0_000_040;
136
137    /// Send fill characters for a delay, rather than using a timed delay.
138    pub const OFILL: c_uint = 0_000_100;
139
140    /// Fill character is ASCII `DEL` (0177).
141    ///
142    /// If unset, fill character is ASCII `NUL` ('\0'). (Not implemented on Linux.)
143    pub const OFDEL: c_uint = 0_000_200;
144
145    /// Newline delay mask.
146    /// Values are [`NL0`](Self::NL0) and [`NL1`](Self::NL1).
147    ///
148    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE` or `_XOPEN_SOURCE`]
149    pub const NLDLY: c_uint = 0_000_400;
150    /// `NLDLY`: Newline type 0_.
151    pub const NL0: c_uint = 0_000_000;
152    /// `NLDLY`: Newline type 1.
153    pub const NL1: c_uint = 0_000_400;
154
155    /// Carriage return delay mask. Values are [`CR0`](Self::CR0),
156    /// [`CR1`](Self::CR1), [`CR2`](Self::CR2), or [`CR3`](Self::CR3).
157    ///
158    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE` or `_XOPEN_SOURCE`]
159    pub const CRDLY: c_uint = 0_003_000;
160    /// `CRDLY`: Carriage-return delay type 0.
161    pub const CR0: c_uint = 0_000_000;
162    /// `CRDLY`: Carriage-return delay type 1.
163    pub const CR1: c_uint = 0_001_000;
164    /// `CRDLY`: Carriage-return delay type 2.
165    pub const CR2: c_uint = 0_002_000;
166    /// `CRDLY`: Carriage-return delay type 3.
167    pub const CR3: c_uint = 0_003_000;
168
169    /// Horizontal tab delay mask.
170    ///
171    /// Values are [`TAB0`](Self::TAB0), [`TAB1`](Self::TAB1),
172    /// [`TAB2`](Self::TAB2), [`TAB3`](Self::TAB3)
173    /// (or `XTABS`, but see the BUGS section).
174    ///
175    /// A value of `TAB3`, that is, `XTABS`, expands tabs to spaces
176    /// (with tab stops every eight columns).
177    ///
178    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE` or `_XOPEN_SOURCE`]
179    ///
180    /// ## BUGS
181    /// On the Alpha architecture before Linux 4.16 (and glibc before
182    /// glibc 2.28), the `XTABS` value was different from `TAB3` and it was
183    /// ignored by the `N_TTY` line discipline code of the terminal driver
184    /// as a result (because as it wasn't part of the `TABDLY` mask).
185    pub const TABDLY: c_uint = 0_014000;
186    /// `TABDLY`: Horizontal-tab delay type 0.
187    pub const TAB0: c_uint = 0_000_000;
188    /// `TABDLY`: Horizontal-tab delay type 1.
189    pub const TAB1: c_uint = 0_004_000;
190    /// `TABDLY`: Horizontal-tab delay type 2.
191    pub const TAB2: c_uint = 0_010_000;
192    /// `TABDLY`: Horizontal-tab delay type 3.
193    pub const TAB3: c_uint = 0_014_000;
194
195    /// Backspace delay mask.
196    /// Values are [`BS0`](Self::BS0) or [`BS1`](Self::BS1).
197    ///
198    /// (Has never been implemented.)
199    ///
200    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE` or `_XOPEN_SOURCE`]
201    pub const BSDLY: c_uint = 0_020_000;
202    /// Backspace-delay type 0.
203    pub const BS0: c_uint = 0_000_000;
204    /// Backspace-delay type 1.
205    pub const BS1: c_uint = 0_020_000;
206
207    /// Vertical tab delay mask.
208    /// Values are [`VT0`](Self::VT0) or [`VT1`](Self::VT1).
209    pub const VTDLY: c_uint = 0_040_000;
210    /// `VTDLY`: Vertical-tab delay type 0.
211    pub const VT0: c_uint = 0_000_000;
212    /// `VTDLY`: Vertical-tab delay type 1.
213    pub const VT1: c_uint = 0_040_000;
214
215    /// Form feed delay mask.
216    /// Values are [`FF0`](Self::FF0) or [`FF1`](Self::FF1).
217    ///
218    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE` or `_XOPEN_SOURCE`]
219    pub const FFDLY: c_uint = 0_100_000;
220    /// `FFDLY`: Form-feed delay type 0.
221    pub const FF0: c_uint = 0_000_000;
222    /// `FFDLY`: Form-feed delay type 1.
223    pub const FF1: c_uint = 0_100_000;
224
225    /// See: [`TAB3`](Self::TAB3)
226    pub const XTABS: c_uint = 0_014_000;
227}
228
229impl LINUX_TERMIOS_CFLAG {
230    /// Character size mask.
231    /// Values are [`CS5`](Self::CS5), [`CS6`](Self::CS5), [`CS7`](Self::CS5),
232    /// or [`CS8`](Self::CS5).
233    pub const CSIZE: c_uint = 0_000_060;
234    /// `CSIZE`: Character size mask type 5.
235    pub const CS5: c_uint = 0_000_000;
236    /// `CSIZE`: Character size mask type 6.
237    pub const CS6: c_uint = 0_000_020;
238    /// `CSIZE`: Character size mask type 7.
239    pub const CS7: c_uint = 0_000_040;
240    /// `CSIZE`: Character size mask type 8.
241    pub const CS8: c_uint = 0_000_060;
242
243    /// Set two stop bits, rather than one.
244    pub const CSTOPB: c_uint = 0_000_100;
245
246    /// Enable receiver.
247    pub const CREAD: c_uint = 0_000_200;
248
249    /// Enable parity generation on output and parity checking for input.
250    pub const PARENB: c_uint = 0_000_400;
251
252    /// If set, then parity for input and output is odd;
253    /// otherwise even parity is used.
254    pub const PARODD: c_uint = 0_001_000;
255
256    /// Lower modem control lines after last process closes the
257    /// device (hang up).
258    pub const HUPCL: c_uint = 0_002_000;
259
260    /// Ignore modem control lines.
261    pub const CLOCAL: c_uint = 0_004_000;
262
263    // (not in POSIX) Baud speed mask (4+1 bits).
264    // [requires _BSD_SOURCE or _SVID_SOURCE]
265    // CBAUD
266
267    // (not in POSIX) Extra baud speed mask (1 bit), included in
268    // CBAUD.  [requires _BSD_SOURCE or _SVID_SOURCE]
269    //
270    // (POSIX says that the baud speed is stored in the termios
271    // structure without specifying where precisely, and provides
272    // cfgetispeed() and cfsetispeed() for getting at it.  Some
273    // systems use bits selected by CBAUD in c_cflag, other
274    // systems use separate fields, for example, sg_ispeed and
275    // sg_ospeed.)
276    // CBAUDEX
277
278    // (not in POSIX) Block output from a noncurrent shell layer.
279    // For use by shl (shell layers).  (Not implemented on
280    // Linux.)
281    // LOBLK
282
283    // (not in POSIX) Mask for input speeds.  The values for the
284    // CIBAUD bits are the same as the values for the CBAUD bits,
285    // shifted left IBSHIFT bits.  [requires _BSD_SOURCE or
286    // _SVID_SOURCE] (Not implemented in glibc, supported on
287    // Linux via TCGET* and TCSET* ioctls; see ioctl_tty(2))
288    // CIBAUD
289
290    // (not in POSIX) Use "stick" (mark/space) parity (supported
291    // on certain serial devices): if PARODD is set, the parity
292    // bit is always 1; if PARODD is not set, then the parity bit
293    // is always 0.  [requires _BSD_SOURCE or _SVID_SOURCE]
294    // CMSPAR
295
296    // (not in POSIX) Enable RTS/CTS (hardware) flow control.
297    // [requires _BSD_SOURCE or _SVID_SOURCE]
298    // CRTSCTS
299}
300
301impl LINUX_TERMIOS_LFLAG {
302    /// Enable signals.
303    ///
304    /// When any of the characters `INTR`, `QUIT`, `SUSP`, or `DSUSP` are
305    /// received, generate the corresponding signal.
306    pub const ISIG: c_uint = 0_000_001;
307
308    /// Enable canonical mode (erase and kill processing).
309    pub const ICANON: c_uint = 0_000_002;
310
311    /// If ICANON is also set, terminal is uppercase only.
312    /// (not in POSIX; not supported under Linux)
313    ///
314    /// Input is converted to lowercase, except for characters preceded by `\`.
315    ///
316    /// On output, uppercase characters are preceded by `\` and lowercase characters
317    /// are converted to uppercase.
318    ///
319    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE` or `_XOPEN_SOURCE`]
320    pub const XCASE: c_uint = 0_000_004;
321
322    /// Echo input characters.
323    pub const ECHO: c_uint = 0_000_010;
324
325    /// If [`ICANON`](Self::ICANON) is also set, the `ERASE` character erases
326    /// the preceding input character, and `WERASE` erases the preceding word.
327    pub const ECHOE: c_uint = 0_000_020;
328
329    /// If [`ICANON`](Self::ICANON) is also set, the `KILL` character
330    /// erases the current line.
331    pub const ECHOK: c_uint = 0_000_040;
332
333    /// If [`ICANON`](Self::ICANON) is also set, echo the `NL` character
334    /// even if [`ECHO`](Self::ECHO) is not set.
335    pub const ECHONL: c_uint = 0_000_100;
336
337    /// Disable flushing the input and output queues when
338    /// generating signals for the `INT`, `QUIT`, and `SUSP` characters.
339    pub const NOFLSH: c_uint = 0_000_200;
340
341    /// Send the `SIGTTOU` signal to the process group of a background process
342    /// which tries to write to its controlling terminal.
343    pub const TOSTOP: c_uint = 0_000_400;
344
345    /// If [`ECHO`](Self::ECHO) is also set, terminal special characters
346    /// other than `TAB`, `NL`, `START`, and `STOP` are echoed as `^X`,
347    /// where `X` is the character with ASCII code `0x40` greater than
348    /// the special character.
349    ///
350    /// (not in POSIX)
351    ///
352    /// For example, character `0x08` (BS) is echoed as `^H`.
353    ///
354    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE`]
355    pub const ECHOCTL: c_uint = 0_001_000;
356
357    /// If [`ICANON`](Self::ICANON) and [`ECHO`](Self::ECHO) are also set,
358    /// characters are printed as they are being erased.
359    ///
360    /// (not in POSIX)
361    ///
362    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE`]
363    pub const ECHOPRT: c_uint = 0_002_000;
364
365    /// If [`ICANON`](Self::ICANON) is also set, `KILL` is echoed by erasing
366    /// each character on the line, as specified by [`ECHOE`](Self::ECHOE)
367    /// and [`ECHOPRT`](Self::ECHOPRT).
368    ///
369    /// (not in POSIX)
370    ///
371    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE`]
372    pub const ECHOKE: c_uint = 0_004_000;
373
374    // /// Echo only when a process is reading.
375    // ///
376    // /// (not in POSIX) (Not implemented on Linux)
377    // pub const DEFECHO: c_uint = ?;
378
379    /// Output is being flushed.
380    ///
381    /// This flag is toggled by typing the `DISCARD` character.
382    ///
383    /// (not in POSIX; not supported under Linux)
384    ///
385    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE`]
386    pub const FLUSHO: c_uint = 0_010_000;
387
388    /// All characters in the input queue are reprinted
389    /// when the next character is read.
390    ///
391    /// (not in POSIX; not supported under Linux)
392    ///
393    /// (bash(1) handles typeahead this way.)
394    ///
395    /// [requires `_BSD_SOURCE` or `_SVID_SOURCE`]
396    pub const PENDING: c_uint = 0_040_000;
397
398    /// Enable implementation-defined input processing.
399    ///
400    /// This flag, as well as [`ICANON`](Self::ICANON) must be enabled for
401    /// the special characters `EOL2`, `LNEXT`, `REPRINT`, `WERASE` to be
402    /// interpreted, and for the [`IUCLC`](LINUX_TERMIOS_IFLAG::IUCLC) flag
403    /// to be effective.
404    pub const IEXTEN: c_uint = 0_100_000;
405
406    /// enable "LINEMODE"; useful with high latency links
407    pub const EXTPROC: c_uint = 0_200_000;
408}