1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
//! This example selects a different skin for ligth or dark terminals
//!
//! Run it with
//! cargo run --example skin
use crossterm::style::{Color, ContentStyle};
struct Skin {
high_contrast: ContentStyle,
low_contrast: ContentStyle,
code: ContentStyle,
}
fn main() {
let skin = match terminal_light::luma() {
Ok(luma) if luma > 0.6 => {
// light theme
Skin {
high_contrast: ContentStyle {
foreground_color: Some(Color::Rgb { r: 40, g: 5, b: 0 }),
..Default::default()
},
low_contrast: ContentStyle {
foreground_color: Some(Color::Rgb {
r: 120,
g: 120,
b: 80,
}),
..Default::default()
},
code: ContentStyle {
foreground_color: Some(Color::Rgb {
r: 50,
g: 50,
b: 50,
}),
background_color: Some(Color::Rgb {
r: 210,
g: 210,
b: 210,
}),
..Default::default()
},
}
}
_ => {
// dark theme
Skin {
high_contrast: ContentStyle {
foreground_color: Some(Color::Rgb {
r: 250,
g: 180,
b: 0,
}),
..Default::default()
},
low_contrast: ContentStyle {
foreground_color: Some(Color::Rgb {
r: 180,
g: 150,
b: 0,
}),
..Default::default()
},
code: ContentStyle {
foreground_color: Some(Color::Rgb {
r: 220,
g: 220,
b: 220,
}),
background_color: Some(Color::Rgb {
r: 80,
g: 80,
b: 80,
}),
..Default::default()
},
}
}
};
println!(
"\n {}",
skin.low_contrast
.apply("This line is easy to read but low intensity")
);
println!(
"\n {}",
skin.high_contrast
.apply("This line has a much greater contrast")
);
println!("\n {}", skin.code.apply("this.is_meant_to_be(some_code);"));
println!();
}
|