libsixel_rs/
config.rs

1//! Configuration settings for the library and binary.
2
3use crate::std::fmt;
4
5/// Loop mode
6#[repr(u8)]
7#[derive(Clone, Copy, Debug, Default, PartialEq)]
8pub enum LoopMode {
9    /// Honor the GIF header setting.
10    #[default]
11    Auto = 0,
12    /// Always enable loop mode.
13    Force,
14    /// Always disable loop mode.
15    Disable,
16}
17
18impl LoopMode {
19    /// Creates a new [LoopMode].
20    pub const fn new() -> Self {
21        Self::Auto
22    }
23}
24
25/// Configuration settings for choosing the palette color space.
26#[repr(u8)]
27#[derive(Clone, Copy, Debug, Default, PartialEq)]
28pub enum PaletteType {
29    /// Choose palette type automatically.
30    #[default]
31    Auto = 0,
32    /// HLS color space.
33    Hls,
34    /// RGB color space.
35    Rgb,
36}
37
38impl PaletteType {
39    /// Creates a new [PaletteType].
40    pub const fn new() -> Self {
41        Self::Auto
42    }
43}
44
45/// Color map settings
46#[repr(u8)]
47#[derive(Clone, Copy, Debug, Default, PartialEq)]
48pub enum ColorOption {
49    /// Use default settings.
50    #[default]
51    Default = 0,
52    /// Use monochrome palette.
53    Monochrome,
54    /// Use builtin palette.
55    Builtin,
56    /// Use mapfile option.
57    Mapfile,
58    /// Use high color option.
59    HighColor,
60}
61
62impl ColorOption {
63    /// Creates a new [ColorOption].
64    pub const fn new() -> Self {
65        Self::Default
66    }
67}
68
69/// Builtin palette selection settings
70#[repr(u8)]
71#[derive(Clone, Copy, Debug, Default, PartialEq)]
72pub enum BuiltinPalette {
73    /// Monochrome terminal with dark background.
74    #[default]
75    MonoDark = 0,
76    /// Monochrome terminal with light background
77    MonoLight,
78    /// xterm 16color
79    Xterm16,
80    /// xterm 256color
81    Xterm256,
82    /// VT340 monochrome
83    Vt340Mono,
84    /// VT340 color
85    Vt340Color,
86    /// 1bit grayscale
87    G1,
88    /// 2bit grayscale
89    G2,
90    /// 4bit grayscale
91    G4,
92    /// 8bit grayscale
93    G8,
94}
95
96impl BuiltinPalette {
97    /// Creates a new [BuiltinPalette].
98    pub const fn new() -> Self {
99        Self::MonoDark
100    }
101}
102
103impl From<u8> for BuiltinPalette {
104    fn from(val: u8) -> Self {
105        match val {
106            v if v == 0 => Self::MonoDark,
107            v if v == 1 => Self::MonoLight,
108            v if v == 2 => Self::Xterm16,
109            v if v == 3 => Self::Xterm256,
110            v if v == 4 => Self::Vt340Mono,
111            v if v == 5 => Self::Vt340Color,
112            v if v == 6 => Self::G1,
113            v if v == 7 => Self::G2,
114            v if v == 8 => Self::G4,
115            v if v == 9 => Self::G8,
116            _ => Self::MonoDark,
117        }
118    }
119}
120
121impl From<bool> for BuiltinPalette {
122    fn from(val: bool) -> Self {
123        (val as u8).into()
124    }
125}
126
127impl From<&BuiltinPalette> for &'static str {
128    fn from(val: &BuiltinPalette) -> Self {
129        match val {
130            BuiltinPalette::MonoDark => "mono dark",
131            BuiltinPalette::MonoLight => "mono light",
132            BuiltinPalette::Xterm16 => "xterm 16-bit",
133            BuiltinPalette::Xterm256 => "xterm 256-bit",
134            BuiltinPalette::Vt340Mono => "vt340 monochrome",
135            BuiltinPalette::Vt340Color => "vt340 color",
136            BuiltinPalette::G1 => "grayscale 1-bit",
137            BuiltinPalette::G2 => "grayscale 2-bit",
138            BuiltinPalette::G4 => "grayscale 4-bit",
139            BuiltinPalette::G8 => "grayscale 8-bit",
140        }
141    }
142}
143
144impl From<BuiltinPalette> for &'static str {
145    fn from(val: BuiltinPalette) -> Self {
146        (&val).into()
147    }
148}
149
150impl fmt::Display for BuiltinPalette {
151    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152        write!(f, "{}", <&str>::from(self))
153    }
154}