4 releases (2 breaking)

0.3.0 Apr 3, 2023
0.2.0 Jun 18, 2022
0.1.3 Dec 13, 2021
0.1.2 Nov 6, 2021

#1510 in Parser implementations

Download history 68/week @ 2023-12-15 90/week @ 2023-12-22 118/week @ 2023-12-29 67/week @ 2024-01-05 84/week @ 2024-01-12 108/week @ 2024-01-19 83/week @ 2024-01-26 107/week @ 2024-02-02 81/week @ 2024-02-09 97/week @ 2024-02-16 142/week @ 2024-02-23 111/week @ 2024-03-01 115/week @ 2024-03-08 127/week @ 2024-03-15 139/week @ 2024-03-22 143/week @ 2024-03-29

539 downloads per month
Used in 2 crates

MIT license

16KB
311 lines

Color -> TUI

build build

Parse HEX colors to ratatui's Rgb colors.

Example

  • #C3F111 -> Color::Rgb(195,241,17)
  • #CFB -> Color::Rgb(204,255,187)
  • 142 -> Color::Indexed(142)

Usage

#[derive(Serialize, Deserialize, PartialEq)]
sruct ColorStruct {
    #[serde(with = "color_to_tui"]
    color: ratatui::style::Color,
    #[serde(with = "color_to_tui::optional"]
    optional_color: Option<ratatui::style::Color>,
}

let color_text =  r###"{ "color" : "#12FC1C", "optional_color" : "123" }"###
let t: ColorStruct = serde_json::from_str::<ColorStruct>(color_text).unwrap();

let c = ColorStruct {
    color: Color::Rgb(18, 252, 28),
    optional_color: Option<Color::Indexed(123)>,
};

assert_eq!(t, c);

Dependencies

~6.5MB
~119K SLoC