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

#1527 in Parser implementations

Download history 31/week @ 2024-11-13 33/week @ 2024-11-20 28/week @ 2024-11-27 29/week @ 2024-12-04 53/week @ 2024-12-11 19/week @ 2024-12-18 4/week @ 2024-12-25 17/week @ 2025-01-01 27/week @ 2025-01-08 28/week @ 2025-01-15 20/week @ 2025-01-22 109/week @ 2025-01-29 79/week @ 2025-02-05 49/week @ 2025-02-12 34/week @ 2025-02-19 44/week @ 2025-02-26

249 downloads per month
Used in nyaa

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

~5MB
~87K SLoC