libsixel_rs/device_control_string/
sixel_control.rs

1use crate::std::fmt;
2
3/// Terminal control characters used in Sixel input mode.
4#[repr(u8)]
5#[derive(Clone, Copy, Debug, Default, PartialEq)]
6pub enum SixelControl {
7    #[default]
8    Parameter = b';',
9    CarriageReturn = b'$',
10    NewLine = b'-',
11    Repeat = b'!',
12    Color = b'#',
13    Raster = b'"',
14}
15
16impl SixelControl {
17    /// Creates a new [SixelControl].
18    pub const fn new() -> Self {
19        Self::Parameter
20    }
21}
22
23impl From<SixelControl> for u8 {
24    fn from(val: SixelControl) -> Self {
25        val as u8
26    }
27}
28
29impl From<&SixelControl> for u8 {
30    fn from(val: &SixelControl) -> Self {
31        (*val).into()
32    }
33}
34
35impl From<SixelControl> for char {
36    fn from(val: SixelControl) -> Self {
37        (val as u8) as char
38    }
39}
40
41impl From<&SixelControl> for char {
42    fn from(val: &SixelControl) -> Self {
43        (*val).into()
44    }
45}
46
47impl fmt::Display for SixelControl {
48    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49        write!(f, "{}", char::from(self))
50    }
51}