Remove dependency on palette
This commit is contained in:
parent
84bf2015ec
commit
fc44a59a6f
3 changed files with 34 additions and 67 deletions
60
Cargo.lock
generated
60
Cargo.lock
generated
|
|
@ -28,15 +28,6 @@ version = "1.0.61"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "508b352bb5c066aac251f6daf6b36eccd03e8a88e8081cd44959ea277a3af9a8"
|
checksum = "508b352bb5c066aac251f6daf6b36eccd03e8a88e8081cd44959ea277a3af9a8"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "approx"
|
|
||||||
version = "0.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-trait"
|
name = "async-trait"
|
||||||
version = "0.1.57"
|
version = "0.1.57"
|
||||||
|
|
@ -194,7 +185,6 @@ dependencies = [
|
||||||
"edit",
|
"edit",
|
||||||
"euphoxide",
|
"euphoxide",
|
||||||
"log",
|
"log",
|
||||||
"palette",
|
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
@ -333,15 +323,6 @@ dependencies = [
|
||||||
"instant",
|
"instant",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "find-crate"
|
|
||||||
version = "0.6.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "59a98bbaacea1c0eb6a0876280051b892eb73594fd90cf3b20e9c817029c57d2"
|
|
||||||
dependencies = [
|
|
||||||
"toml",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fnv"
|
name = "fnv"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
|
|
@ -629,15 +610,6 @@ dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-traits"
|
|
||||||
version = "0.2.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num_cpus"
|
name = "num_cpus"
|
||||||
version = "1.13.1"
|
version = "1.13.1"
|
||||||
|
|
@ -675,29 +647,6 @@ version = "6.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4"
|
checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "palette"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8f9cd68f7112581033f157e56c77ac4a5538ec5836a2e39284e65bd7d7275e49"
|
|
||||||
dependencies = [
|
|
||||||
"approx",
|
|
||||||
"num-traits",
|
|
||||||
"palette_derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "palette_derive"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "05eedf46a8e7c27f74af0c9cfcdb004ceca158cb1b918c6f68f8d7a549b3e427"
|
|
||||||
dependencies = [
|
|
||||||
"find-crate",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
|
|
@ -1249,15 +1198,6 @@ dependencies = [
|
||||||
"webpki",
|
"webpki",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml"
|
|
||||||
version = "0.5.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toss"
|
name = "toss"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ crossterm = "0.25.0"
|
||||||
directories = "4.0.1"
|
directories = "4.0.1"
|
||||||
edit = "0.1.4"
|
edit = "0.1.4"
|
||||||
log = { version = "0.4.17", features = ["std"] }
|
log = { version = "0.4.17", features = ["std"] }
|
||||||
palette = { version = "0.6.1", default-features = false, features = ["std"] }
|
|
||||||
parking_lot = "0.12.1"
|
parking_lot = "0.12.1"
|
||||||
rusqlite = { version = "0.28.0", features = ["bundled", "time"] }
|
rusqlite = { version = "0.28.0", features = ["bundled", "time"] }
|
||||||
serde_json = "1.0.83"
|
serde_json = "1.0.83"
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,40 @@
|
||||||
use crossterm::style::{Color, ContentStyle, Stylize};
|
use crossterm::style::{Color, ContentStyle, Stylize};
|
||||||
use palette::{FromColor, Hsl, RgbHue, Srgb};
|
|
||||||
|
/// Convert HSL to RGB following [this approach from wikipedia][1].
|
||||||
|
///
|
||||||
|
/// `h` must be in the range `[0, 360]`, `s` and `l` in the range `[0, 1]`.
|
||||||
|
///
|
||||||
|
/// [1]: https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB
|
||||||
|
fn hsl_to_rgb(h: f32, s: f32, l: f32) -> (u8, u8, u8) {
|
||||||
|
assert!((0.0..=360.0).contains(&h), "h must be in range [0, 360]");
|
||||||
|
assert!((0.0..=1.0).contains(&s), "s must be in range [0, 1]");
|
||||||
|
assert!((0.0..=1.0).contains(&l), "l must be in range [0, 1]");
|
||||||
|
|
||||||
|
let c = (1.0 - (2.0 * l - 1.0).abs()) * s;
|
||||||
|
|
||||||
|
let h_prime = h / 60.0;
|
||||||
|
let x = c * (1.0 - (h_prime.rem_euclid(2.0) - 1.0).abs());
|
||||||
|
|
||||||
|
let (r1, g1, b1) = match () {
|
||||||
|
_ if h_prime < 1.0 => (c, x, 0.0),
|
||||||
|
_ if h_prime < 2.0 => (x, c, 0.0),
|
||||||
|
_ if h_prime < 3.0 => (0.0, c, x),
|
||||||
|
_ if h_prime < 4.0 => (0.0, x, c),
|
||||||
|
_ if h_prime < 5.0 => (x, 0.0, c),
|
||||||
|
_ => (c, 0.0, x),
|
||||||
|
};
|
||||||
|
|
||||||
|
let m = l - c / 2.0;
|
||||||
|
let (r, g, b) = (r1 + m, g1 + m, b1 + m);
|
||||||
|
|
||||||
|
// The rgb values in the range [0,1] are each split into 256 segments of the
|
||||||
|
// same length, which are then assigned to the 256 possible values of an u8.
|
||||||
|
((r * 256.0) as u8, (g * 256.0) as u8, (b * 256.0) as u8)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn nick_color(nick: &str) -> (u8, u8, u8) {
|
pub fn nick_color(nick: &str) -> (u8, u8, u8) {
|
||||||
let hue = RgbHue::from(euphoxide::nick_hue(nick) as f32);
|
let hue = euphoxide::nick_hue(nick) as f32;
|
||||||
let color = Hsl::new(hue, 1.0, 0.72);
|
hsl_to_rgb(hue, 1.0, 0.72)
|
||||||
Srgb::from_color(color)
|
|
||||||
.into_format::<u8>()
|
|
||||||
.into_components()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nick_style(nick: &str) -> ContentStyle {
|
pub fn nick_style(nick: &str) -> ContentStyle {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue