ptouch_rs/
text_color.rs

1use nom::{IResult, number::complete::u8};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5pub enum TextColor {
6  None,
7  Black,
8  Blue,
9  BlueF,
10  Cleaning,
11  Gold,
12  Incompatible,
13  Red,
14  Stencil,
15  White,
16  Other,
17  Unknown(u8),
18}
19
20impl From<u8> for TextColor {
21  fn from(value: u8) -> Self {
22    match value {
23      0x00 => TextColor::None,
24      0x01 => TextColor::White,
25      0x02 => TextColor::Other,
26      0x04 => TextColor::Red,
27      0x05 => TextColor::Blue,
28      0x08 => TextColor::Black,
29      0x0a => TextColor::Gold,
30      0x62 => TextColor::BlueF,
31      0xf0 => TextColor::Cleaning,
32      0xf1 => TextColor::Stencil,
33      0xff => TextColor::Incompatible,
34      v => TextColor::Unknown(v),
35    }
36  }
37}
38
39impl TextColor {
40  pub fn parse(input: &[u8]) -> IResult<&[u8], Self> {
41    let (input, color) = u8(input)?;
42
43    Ok((input, color.into()))
44  }
45}