Skip to main content

devela/sys/os/linux/io/term/
flags.rs

1// devela::sys::os::linux::io::term::flags
2
3#[cfg(doc)]
4use crate::LinuxTermios;
5use crate::{
6    LINUX_TERMIOS_CFLAG as C, LINUX_TERMIOS_IFLAG as I, LINUX_TERMIOS_LFLAG as L,
7    LINUX_TERMIOS_OFLAG as O,
8};
9use crate::{c_uint, set};
10
11set! {
12    #[doc = crate::_tags!(linux term set)]
13    /// [`LinuxTermios`] input flags.
14    #[doc = crate::_doc_meta!{
15        location("sys/os/term/session"),
16        test_size_of(LinuxTermiosInputFlags = 2|16),
17    }]
18    ///
19    pub struct LinuxTermiosInputFlags(u16) {
20        /// Ignore BREAK condition on input.
21        IGNBRK  = 0;
22        /// Signal interrupt on BREAK.
23        BRKINT  = 1;
24        /// Ignore framing errors and parity errors.
25        IGNPAR  = 2;
26        /// Mark parity and framing errors.
27        PARMRK  = 3;
28        /// Enable input parity checking.
29        INPCK   = 4;
30        /// Strip off eighth bit.
31        ISTRIP  = 5;
32        /// Translate `NL` to `CR` on input.
33        INLCR   = 6;
34        /// Ignore `CR` on input.
35        IGNCR   = 7;
36        /// Translate `CR` to `NL` on input.
37        ICRNL   = 8;
38        /// Map uppercase characters to lowercase on input.
39        IUCLC   = 9;
40        /// Enable XON/XOFF flow control on output.
41        IXON    = 10;
42        /// Any character restarts stopped output.
43        IXANY   = 11;
44        /// Enable XON/XOFF flow control on input.
45        IXOFF   = 12;
46        /// Ring bell when input queue is full.
47        IMAXBEL = 13;
48        /// Input is UTF-8.
49        IUTF8   = 14;
50    }
51    impl {
52        /// Returns flags from the raw Linux `c_iflag` word.
53        #[must_use]
54        pub const fn from_c_uint(bits: c_uint) -> Self {
55            Self::from_bits(bits as u16)
56        }
57        /// Returns flags as a raw Linux `c_iflag` word.
58        #[must_use]
59        pub const fn as_c_uint(self) -> c_uint {
60            self.bits() as c_uint
61        }
62        const _ASSERT_RAW_VALUES: () = {
63            assert!(Self::IGNBRK.as_c_uint()  == I::IGNBRK);
64            assert!(Self::BRKINT.as_c_uint()  == I::BRKINT);
65            assert!(Self::IGNPAR.as_c_uint()  == I::IGNPAR);
66            assert!(Self::PARMRK.as_c_uint()  == I::PARMRK);
67            assert!(Self::INPCK.as_c_uint()   == I::INPCK);
68            assert!(Self::ISTRIP.as_c_uint()  == I::ISTRIP);
69            assert!(Self::INLCR.as_c_uint()   == I::INLCR);
70            assert!(Self::IGNCR.as_c_uint()   == I::IGNCR);
71            assert!(Self::ICRNL.as_c_uint()   == I::ICRNL);
72            assert!(Self::IUCLC.as_c_uint()   == I::IUCLC);
73            assert!(Self::IXON.as_c_uint()    == I::IXON);
74            assert!(Self::IXANY.as_c_uint()   == I::IXANY);
75            assert!(Self::IXOFF.as_c_uint()   == I::IXOFF);
76            assert!(Self::IMAXBEL.as_c_uint() == I::IMAXBEL);
77            assert!(Self::IUTF8.as_c_uint()   == I::IUTF8);
78        };
79    }
80}
81set! {
82    #[doc = crate::_tags!(linux term set)]
83    /// [`LinuxTermios`] output flags.
84    #[doc = crate::_doc_meta!{
85        location("sys/os/term/session"),
86        test_size_of(LinuxTermiosOutputFlags = 4|32),
87    }]
88    ///
89    /// NOTE: Some constants in this group are masked delay fields,
90    /// not independent boolean flags. Prefer field-specific helpers
91    /// when they exist instead of combining delay values manually.
92    pub struct LinuxTermiosOutputFlags(u32) {
93        /// Enable implementation-defined output processing.
94        OPOST  = 0;
95        /// Map lowercase characters to uppercase on output.
96        OLCUC  = 1;
97        /// Map `NL` to `CR-NL` on output.
98        ONLCR  = 2;
99        /// Map `CR` to `NL` on output.
100        OCRNL  = 3;
101        /// Don't output `CR` at column 0.
102        ONOCR  = 4;
103        /// `NL` performs carriage-return.
104        ONLRET = 5;
105        /// Send fill characters for a delay.
106        OFILL  = 6;
107        /// Fill character is ASCII `DEL`.
108        OFDEL  = 7;
109
110        /// Newline delay mask.
111        NLDLY = 8;
112        /// Newline delay type 1.
113        NL1   = 8;
114
115        /// Carriage-return delay mask.
116        CRDLY = 9..=10;
117        /// Carriage-return delay type 1.
118        CR1   = 9;
119        /// Carriage-return delay type 2.
120        CR2   = 10;
121        /// Carriage-return delay type 3.
122        CR3   = 9..=10;
123
124        /// Horizontal-tab delay mask.
125        TABDLY = 11..=12;
126        /// Horizontal-tab delay type 1.
127        TAB1   = 11;
128        /// Horizontal-tab delay type 2.
129        TAB2   = 12;
130        /// Horizontal-tab delay type 3.
131        TAB3   = 11..=12;
132
133        /// Backspace delay mask.
134        BSDLY = 13;
135        /// Backspace delay type 1.
136        BS1   = 13;
137
138        /// Vertical-tab delay mask.
139        VTDLY = 14;
140        /// Vertical-tab delay type 1.
141        VT1   = 14;
142
143        /// Form-feed delay mask.
144        FFDLY = 15;
145        /// Form-feed delay type 1.
146        FF1   = 15;
147
148        /// Expands tabs to spaces. Same value as [`TAB3`](Self::TAB3).
149        XTABS = 11..=12;
150    }
151    impl {
152        /// Newline delay type 0.
153        pub const NL0: Self = Self::new();
154        /// Carriage-return delay type 0.
155        pub const CR0: Self = Self::new();
156        /// Horizontal-tab delay type 0.
157        pub const TAB0: Self = Self::new();
158        /// Backspace delay type 0.
159        pub const BS0: Self = Self::new();
160        /// Vertical-tab delay type 0.
161        pub const VT0: Self = Self::new();
162        /// Form-feed delay type 0.
163        pub const FF0: Self = Self::new();
164
165        /// Returns flags from the raw Linux `c_oflag` word.
166        #[must_use]
167        pub const fn from_c_uint(bits: c_uint) -> Self {
168            Self::from_bits(bits)
169        }
170        /// Returns flags as a raw Linux `c_oflag` word.
171        #[must_use]
172        pub const fn as_c_uint(self) -> c_uint {
173            self.bits()
174        }
175        const _ASSERT_RAW_VALUES: () = {
176            assert!(Self::OPOST.as_c_uint()  == O::OPOST);
177            assert!(Self::OLCUC.as_c_uint()  == O::OLCUC);
178            assert!(Self::ONLCR.as_c_uint()  == O::ONLCR);
179            assert!(Self::OCRNL.as_c_uint()  == O::OCRNL);
180            assert!(Self::ONOCR.as_c_uint()  == O::ONOCR);
181            assert!(Self::ONLRET.as_c_uint() == O::ONLRET);
182            assert!(Self::OFILL.as_c_uint()  == O::OFILL);
183            assert!(Self::OFDEL.as_c_uint()  == O::OFDEL);
184
185            assert!(Self::NLDLY.as_c_uint() == O::NLDLY);
186            assert!(Self::NL0.as_c_uint()   == O::NL0);
187            assert!(Self::NL1.as_c_uint()   == O::NL1);
188
189            assert!(Self::CRDLY.as_c_uint() == O::CRDLY);
190            assert!(Self::CR0.as_c_uint()   == O::CR0);
191            assert!(Self::CR1.as_c_uint()   == O::CR1);
192            assert!(Self::CR2.as_c_uint()   == O::CR2);
193            assert!(Self::CR3.as_c_uint()   == O::CR3);
194
195            assert!(Self::TABDLY.as_c_uint() == O::TABDLY);
196            assert!(Self::TAB0.as_c_uint()   == O::TAB0);
197            assert!(Self::TAB1.as_c_uint()   == O::TAB1);
198            assert!(Self::TAB2.as_c_uint()   == O::TAB2);
199            assert!(Self::TAB3.as_c_uint()   == O::TAB3);
200            assert!(Self::XTABS.as_c_uint()  == O::XTABS);
201
202            assert!(Self::BSDLY.as_c_uint() == O::BSDLY);
203            assert!(Self::BS0.as_c_uint()   == O::BS0);
204            assert!(Self::BS1.as_c_uint()   == O::BS1);
205
206            assert!(Self::VTDLY.as_c_uint() == O::VTDLY);
207            assert!(Self::VT0.as_c_uint()   == O::VT0);
208            assert!(Self::VT1.as_c_uint()   == O::VT1);
209
210            assert!(Self::FFDLY.as_c_uint() == O::FFDLY);
211            assert!(Self::FF0.as_c_uint()   == O::FF0);
212            assert!(Self::FF1.as_c_uint()   == O::FF1);
213        };
214    }
215}
216set! {
217    #[doc = crate::_tags!(linux term set)]
218    /// [`LinuxTermios`] control flags.
219    #[doc = crate::_doc_meta!{
220        location("sys/os/linux/io/term"),
221        test_size_of(LinuxTermiosControlFlags = 2|16),
222    }]
223    /// NOTE: `CSIZE`/`CS5`/`CS6`/`CS7`/`CS8` are a masked character-size field,
224    /// not independent flags. Prefer [`LinuxTermios::set_char_size`] when changing it.
225    pub struct LinuxTermiosControlFlags(u16) {
226        /// Character size mask.
227        CSIZE  = 4..=5;
228        /// Character size 6 bits.
229        CS6    = 4;
230        /// Character size 7 bits.
231        CS7    = 5;
232        /// Character size 8 bits.
233        CS8    = 4..=5;
234
235        /// Set two stop bits, rather than one.
236        CSTOPB = 6;
237        /// Enable receiver.
238        CREAD  = 7;
239        /// Enable parity generation and checking.
240        PARENB = 8;
241        /// Odd parity instead of even parity.
242        PARODD = 9;
243        /// Hang up on last close.
244        HUPCL  = 10;
245        /// Ignore modem control lines.
246        CLOCAL = 11;
247    }
248    impl {
249        /// Character size 5 bits.
250        pub const CS5: Self = Self::new();
251
252        /// Returns flags from the raw Linux `c_cflag` word.
253        #[must_use]
254        pub const fn from_c_uint(bits: c_uint) -> Self {
255            Self::from_bits(bits as u16)
256        }
257        /// Returns flags as a raw Linux `c_cflag` word.
258        #[must_use]
259        pub const fn as_c_uint(self) -> c_uint {
260            self.bits() as c_uint
261        }
262        const _ASSERT_RAW_VALUES: () = {
263            assert!(Self::CSIZE.as_c_uint()  == C::CSIZE);
264            assert!(Self::CS5.as_c_uint()    == C::CS5);
265            assert!(Self::CS6.as_c_uint()    == C::CS6);
266            assert!(Self::CS7.as_c_uint()    == C::CS7);
267            assert!(Self::CS8.as_c_uint()    == C::CS8);
268            assert!(Self::CSTOPB.as_c_uint() == C::CSTOPB);
269            assert!(Self::CREAD.as_c_uint()  == C::CREAD);
270            assert!(Self::PARENB.as_c_uint() == C::PARENB);
271            assert!(Self::PARODD.as_c_uint() == C::PARODD);
272            assert!(Self::HUPCL.as_c_uint()  == C::HUPCL);
273            assert!(Self::CLOCAL.as_c_uint() == C::CLOCAL);
274        };
275    }
276}
277set! {
278    #[doc = crate::_tags!(linux term set)]
279    /// [`LinuxTermios`] local flags.
280    #[doc = crate::_doc_meta!{
281        location("sys/os/linux/io/term"),
282        test_size_of(LinuxTermiosLocalFlags = 4|32),
283    }]
284    pub struct LinuxTermiosLocalFlags(u32) {
285        /// Enable signals.
286        ISIG    = 0;
287        /// Enable canonical mode.
288        ICANON  = 1;
289        /// Uppercase-only terminal compatibility mode.
290        XCASE   = 2;
291        /// Echo input characters.
292        ECHO    = 3;
293        /// Echo erase processing.
294        ECHOE   = 4;
295        /// Echo kill processing.
296        ECHOK   = 5;
297        /// Echo newline.
298        ECHONL  = 6;
299        /// Disable flushing when generating signals.
300        NOFLSH  = 7;
301        /// Send `SIGTTOU` for background output.
302        TOSTOP  = 8;
303        /// Echo control characters as `^X`.
304        ECHOCTL = 9;
305        /// Visual erase mode.
306        ECHOPRT = 10;
307        /// Echo line kill by erasing each character.
308        ECHOKE  = 11;
309        /// Output is being flushed.
310        FLUSHO  = 12;
311        /// Pending input reprint.
312        PENDING = 14;
313        /// Enable implementation-defined input processing.
314        IEXTEN  = 15;
315        /// External processing.
316        EXTPROC = 16;
317    }
318    impl {
319        /// Returns flags from the raw Linux `c_lflag` word.
320        #[must_use]
321        pub const fn from_c_uint(bits: c_uint) -> Self {
322            Self::from_bits(bits)
323        }
324        /// Returns flags as a raw Linux `c_lflag` word.
325        #[must_use]
326        pub const fn as_c_uint(self) -> c_uint {
327            self.bits()
328        }
329        const _ASSERT_RAW_VALUES: () = {
330            assert!(Self::ISIG.as_c_uint()    == L::ISIG);
331            assert!(Self::ICANON.as_c_uint()  == L::ICANON);
332            assert!(Self::XCASE.as_c_uint()   == L::XCASE);
333            assert!(Self::ECHO.as_c_uint()    == L::ECHO);
334            assert!(Self::ECHOE.as_c_uint()   == L::ECHOE);
335            assert!(Self::ECHOK.as_c_uint()   == L::ECHOK);
336            assert!(Self::ECHONL.as_c_uint()  == L::ECHONL);
337            assert!(Self::NOFLSH.as_c_uint()  == L::NOFLSH);
338            assert!(Self::TOSTOP.as_c_uint()  == L::TOSTOP);
339            assert!(Self::ECHOCTL.as_c_uint() == L::ECHOCTL);
340            assert!(Self::ECHOPRT.as_c_uint() == L::ECHOPRT);
341            assert!(Self::ECHOKE.as_c_uint()  == L::ECHOKE);
342            assert!(Self::FLUSHO.as_c_uint()  == L::FLUSHO);
343            assert!(Self::PENDING.as_c_uint() == L::PENDING);
344            assert!(Self::IEXTEN.as_c_uint()  == L::IEXTEN);
345            assert!(Self::EXTPROC.as_c_uint() == L::EXTPROC);
346        };
347    }
348}