Skip to content

uttarayan21/color-to-tui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

About

Parse hex colors to tui::style::Color

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages