From 5431651631face108b916f2cf3741649d7a2e0ce Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Sun, 3 Jul 2022 21:58:51 +0530 Subject: [PATCH] Bump crossterm to 0.24.0 --- CHANGELOG.md | 1 + Cargo.lock | 127 ++++++++++++++++++++++++++++++++------------- Cargo.toml | 2 +- src/color/theme.rs | 113 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 204 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5db464e..0f1671d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed ### Fixed +- Fix rendering issues in Windows from [meain](https://gitHub.com/meain) ## [0.22.0] - 2022-06-12 ### Added diff --git a/Cargo.lock b/Cargo.lock index 08916ce..9f4bd4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,9 +76,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bstr" @@ -147,15 +147,15 @@ dependencies = [ [[package]] name = "crossterm" -version = "0.21.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486d44227f71a1ef39554c0dc47e44b9f4139927c75043312690c3f476d1d788" +checksum = "ab9f7409c70a38a56216480fba371ee460207dd8926ccf5b4160591759559170" dependencies = [ "bitflags", "crossterm_winapi", "libc", "mio", - "parking_lot", + "parking_lot 0.12.1", "serde", "signal-hook", "signal-hook-mio", @@ -164,9 +164,9 @@ dependencies = [ [[package]] name = "crossterm_winapi" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a6966607622438301997d3dac0d2f6e9a90c68bb6bc1785ea98456ab93c0507" +checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" dependencies = [ "winapi", ] @@ -247,7 +247,7 @@ checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.10.2+wasi-snapshot-preview1", ] [[package]] @@ -450,24 +450,14 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "mio" -version = "0.7.14" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" dependencies = [ "libc", "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys", ] [[package]] @@ -476,15 +466,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" -[[package]] -name = "ntapi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" -dependencies = [ - "winapi", -] - [[package]] name = "num-integer" version = "0.1.44" @@ -518,7 +499,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core", + "parking_lot_core 0.8.5", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core 0.9.3", ] [[package]] @@ -535,6 +526,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "parking_lot_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + [[package]] name = "percent-encoding" version = "2.1.0" @@ -711,7 +715,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d" dependencies = [ "lazy_static", - "parking_lot", + "parking_lot 0.11.2", "serial_test_derive", ] @@ -728,9 +732,9 @@ dependencies = [ [[package]] name = "signal-hook" -version = "0.3.9" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "470c5a6397076fae0094aaf06a08e6ba6f37acb77d3b1b91ea92b4d6c8650c39" +checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" dependencies = [ "libc", "signal-hook-registry", @@ -738,9 +742,9 @@ dependencies = [ [[package]] name = "signal-hook-mio" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29fd5867f1c4f2c5be079aee7a2adf1152ebb04a4bc4d341f504b7dece607ed4" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" dependencies = [ "libc", "mio", @@ -978,6 +982,12 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wild" version = "2.0.4" @@ -1018,6 +1028,49 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + [[package]] name = "xattr" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index c207dc7..8fc29e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ clap = "2.33.*" version_check = "0.9.*" [dependencies] -crossterm = { version = "0.21.0", features = ["serde"]} +crossterm = { version = "0.24.0", features = ["serde"]} dirs = "3.0.*" libc = "0.2.*" human-sort = "0.2.2" diff --git a/src/color/theme.rs b/src/color/theme.rs index 03d057f..e02d505 100644 --- a/src/color/theme.rs +++ b/src/color/theme.rs @@ -5,8 +5,83 @@ use crate::print_error; use crossterm::style::Color; use serde::Deserialize; -use std::fs; use std::path::Path; +use std::{fmt, fs}; + +// Custom color deserialize +fn deserialize_color<'de, D>(deserializer: D) -> Result +where + D: serde::de::Deserializer<'de>, +{ + struct ColorVisitor; + impl<'de> serde::de::Visitor<'de> for ColorVisitor { + type Value = Color; + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str( + "`black`, `blue`, `dark_blue`, `cyan`, `dark_cyan`, `green`, `dark_green`, `grey`, `dark_grey`, `magenta`, `dark_magenta`, `red`, `dark_red`, `white`, `yellow`, `dark_yellow`, `u8`, or `3 u8 array`", + ) + } + fn visit_str(self, value: &str) -> Result + where + E: serde::de::Error, + { + if let Ok(c) = Color::try_from(value) { + Ok(c) + } else { + Err(E::invalid_value(serde::de::Unexpected::Str(value), &self)) + } + } + + fn visit_u64(self, value: u64) -> Result + where + E: serde::de::Error, + { + if value > 255 { + return Err(E::invalid_value( + serde::de::Unexpected::Unsigned(value), + &self, + )); + } + Ok(Color::AnsiValue(value as u8)) + } + + fn visit_seq(self, mut seq: M) -> Result + where + M: serde::de::SeqAccess<'de>, + { + let mut values = Vec::new(); + if let Some(size) = seq.size_hint() { + if size != 3 { + return Err(serde::de::Error::invalid_length( + size, + &"a list of size 3(RGB)", + )); + } + } + loop { + match seq.next_element::() { + Ok(Some(x)) => { + values.push(x); + } + Ok(None) => break, + Err(e) => { + return Err(e); + } + } + } + // recheck as size_hint sometimes not working + if values.len() != 3 { + return Err(serde::de::Error::invalid_length( + values.len(), + &"a list of size 3(RGB)", + )); + } + Ok(Color::from((values[0], values[1], values[2]))) + } + } + + deserializer.deserialize_any(ColorVisitor) +} /// A struct holding the theme configuration /// Color table: https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.avg @@ -15,12 +90,15 @@ use std::path::Path; #[serde(deny_unknown_fields)] #[serde(default)] pub struct Theme { + #[serde(deserialize_with = "deserialize_color")] pub user: Color, + #[serde(deserialize_with = "deserialize_color")] pub group: Color, pub permission: Permission, pub date: Date, pub size: Size, pub inode: INode, + #[serde(deserialize_with = "deserialize_color")] pub tree_edge: Color, pub links: Links, @@ -33,13 +111,21 @@ pub struct Theme { #[serde(deny_unknown_fields)] #[serde(default)] pub struct Permission { + #[serde(deserialize_with = "deserialize_color")] pub read: Color, + #[serde(deserialize_with = "deserialize_color")] pub write: Color, + #[serde(deserialize_with = "deserialize_color")] pub exec: Color, + #[serde(deserialize_with = "deserialize_color")] pub exec_sticky: Color, + #[serde(deserialize_with = "deserialize_color")] pub no_access: Color, + #[serde(deserialize_with = "deserialize_color")] pub octal: Color, + #[serde(deserialize_with = "deserialize_color")] pub acl: Color, + #[serde(deserialize_with = "deserialize_color")] pub context: Color, } @@ -50,11 +136,16 @@ pub struct Permission { pub struct FileType { pub file: File, pub dir: Dir, + #[serde(deserialize_with = "deserialize_color")] pub pipe: Color, pub symlink: Symlink, + #[serde(deserialize_with = "deserialize_color")] pub block_device: Color, + #[serde(deserialize_with = "deserialize_color")] pub char_device: Color, + #[serde(deserialize_with = "deserialize_color")] pub socket: Color, + #[serde(deserialize_with = "deserialize_color")] pub special: Color, } @@ -63,9 +154,13 @@ pub struct FileType { #[serde(deny_unknown_fields)] #[serde(default)] pub struct File { + #[serde(deserialize_with = "deserialize_color")] pub exec_uid: Color, + #[serde(deserialize_with = "deserialize_color")] pub uid_no_exec: Color, + #[serde(deserialize_with = "deserialize_color")] pub exec_no_uid: Color, + #[serde(deserialize_with = "deserialize_color")] pub no_exec_no_uid: Color, } @@ -74,7 +169,9 @@ pub struct File { #[serde(deny_unknown_fields)] #[serde(default)] pub struct Dir { + #[serde(deserialize_with = "deserialize_color")] pub uid: Color, + #[serde(deserialize_with = "deserialize_color")] pub no_uid: Color, } @@ -83,8 +180,11 @@ pub struct Dir { #[serde(deny_unknown_fields)] #[serde(default)] pub struct Symlink { + #[serde(deserialize_with = "deserialize_color")] pub default: Color, + #[serde(deserialize_with = "deserialize_color")] pub broken: Color, + #[serde(deserialize_with = "deserialize_color")] pub missing_target: Color, } @@ -93,8 +193,11 @@ pub struct Symlink { #[serde(deny_unknown_fields)] #[serde(default)] pub struct Date { + #[serde(deserialize_with = "deserialize_color")] pub hour_old: Color, + #[serde(deserialize_with = "deserialize_color")] pub day_old: Color, + #[serde(deserialize_with = "deserialize_color")] pub older: Color, } @@ -103,9 +206,13 @@ pub struct Date { #[serde(deny_unknown_fields)] #[serde(default)] pub struct Size { + #[serde(deserialize_with = "deserialize_color")] pub none: Color, + #[serde(deserialize_with = "deserialize_color")] pub small: Color, + #[serde(deserialize_with = "deserialize_color")] pub medium: Color, + #[serde(deserialize_with = "deserialize_color")] pub large: Color, } @@ -114,7 +221,9 @@ pub struct Size { #[serde(deny_unknown_fields)] #[serde(default)] pub struct INode { + #[serde(deserialize_with = "deserialize_color")] pub valid: Color, + #[serde(deserialize_with = "deserialize_color")] pub invalid: Color, } @@ -123,7 +232,9 @@ pub struct INode { #[serde(deny_unknown_fields)] #[serde(default)] pub struct Links { + #[serde(deserialize_with = "deserialize_color")] pub valid: Color, + #[serde(deserialize_with = "deserialize_color")] pub invalid: Color, }