From 90d31e4cbefb3a46d2f3b5b5942a0837e4db839d Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 12 Jan 2025 01:54:38 +0100 Subject: [PATCH] fixes --- .github/workflows/test.yml | 8 +------- Cargo.toml | 5 ++++- src/color.rs | 4 +--- src/control.rs | 3 +++ src/customcolors.rs | 3 ++- src/style.rs | 27 ++++++++++++++++++--------- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26d2b58..6079ee4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,8 +11,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - with: - lfs: true - name: Install Rust stable uses: dtolnay/rust-toolchain@master with: @@ -30,8 +28,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - with: - lfs: true - name: Install Rust stable uses: dtolnay/rust-toolchain@master with: @@ -46,12 +42,10 @@ jobs: strategy: matrix: os: ["ubuntu", "windows", "macos"] - version: ["stable", "beta", "1.84"] + version: ["stable", "beta", "1.80"] steps: - name: Checkout repository uses: actions/checkout@v4 - with: - lfs: true - name: Install Rust ${{ matrix.version }} uses: dtolnay/rust-toolchain@master with: diff --git a/Cargo.toml b/Cargo.toml index 1059c8f..9d05471 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ insta = "1" rspec = "1" [lints.rust] -unsafe_code = "forbid" +unsafe_code = "warn" deprecated = "warn" [lints.clippy] @@ -40,6 +40,9 @@ suspicious = "warn" # Could be enabled in the future too_many_lines = { level = "allow", priority = 10 } +unwrap_used = { level = "allow", priority = 10 } +expect_used = { level = "allow", priority = 10 } +wildcard_imports = { level = "allow", priority = 10 } # not necessary module_name_repetitions = { level = "allow", priority = 10 } diff --git a/src/color.rs b/src/color.rs index 948d481..1819651 100644 --- a/src/color.rs +++ b/src/color.rs @@ -28,9 +28,7 @@ pub enum Color { fn truecolor_support() -> bool { let truecolor = env::var("COLORTERM"); - truecolor.map_or(false, |truecolor| { - truecolor == "truecolor" || truecolor == "24bit" - }) + truecolor.is_ok_and(|truecolor| truecolor == "truecolor" || truecolor == "24bit") } #[allow(missing_docs)] diff --git a/src/control.rs b/src/control.rs index 343731a..4ba50b8 100644 --- a/src/control.rs +++ b/src/control.rs @@ -26,6 +26,8 @@ use std::sync::LazyLock; /// control::set_virtual_terminal(true).unwrap(); /// println!("{}", "bright cyan".bright_cyan()); // will print correctly /// ``` +/// # Errors +/// This function will return `Ok(())` if the operation was successful. #[allow(clippy::result_unit_err)] #[cfg(windows)] pub fn set_virtual_terminal(use_virtual: bool) -> Result<(), ()> { @@ -34,6 +36,7 @@ pub fn set_virtual_terminal(use_virtual: bool) -> Result<(), ()> { STD_OUTPUT_HANDLE, }; + #[allow(unsafe_code)] // needed here unsafe { let handle = GetStdHandle(STD_OUTPUT_HANDLE); let mut original_mode = 0; diff --git a/src/customcolors.rs b/src/customcolors.rs index 3e7dd1c..fcf6982 100644 --- a/src/customcolors.rs +++ b/src/customcolors.rs @@ -12,7 +12,8 @@ pub struct CustomColor { /// This only makes custom color creation easier. impl CustomColor { /// Create a new custom color - #[must_use] pub const fn new(r: u8, g: u8, b: u8) -> Self { + #[must_use] + pub const fn new(r: u8, g: u8, b: u8) -> Self { Self { r, g, b } } } diff --git a/src/style.rs b/src/style.rs index 39b4299..0bac666 100644 --- a/src/style.rs +++ b/src/style.rs @@ -339,7 +339,8 @@ impl Style { /// assert_eq!(colored.style.contains(Styles::Italic), true); /// assert_eq!(colored.style.contains(Styles::Dimmed), false); /// ``` - #[must_use] pub const fn contains(self, style: Styles) -> bool { + #[must_use] + pub const fn contains(self, style: Styles) -> bool { let s = style.to_u8(); self.0 & s == s } @@ -389,49 +390,57 @@ impl Style { } /// Makes this `Style` include Bold. - #[must_use] pub fn bold(mut self) -> Self { + #[must_use] + pub fn bold(mut self) -> Self { self.add(Styles::Bold); self } /// Makes this `Style` include Dimmed. - #[must_use] pub fn dimmed(mut self) -> Self { + #[must_use] + pub fn dimmed(mut self) -> Self { self.add(Styles::Dimmed); self } /// Makes this `Style` include Underline. - #[must_use] pub fn underline(mut self) -> Self { + #[must_use] + pub fn underline(mut self) -> Self { self.add(Styles::Underline); self } /// Makes this `Style` include Reversed. - #[must_use] pub fn reversed(mut self) -> Self { + #[must_use] + pub fn reversed(mut self) -> Self { self.add(Styles::Reversed); self } /// Makes this `Style` include Italic. - #[must_use] pub fn italic(mut self) -> Self { + #[must_use] + pub fn italic(mut self) -> Self { self.add(Styles::Italic); self } /// Makes this `Style` include Blink. - #[must_use] pub fn blink(mut self) -> Self { + #[must_use] + pub fn blink(mut self) -> Self { self.add(Styles::Blink); self } /// Makes this `Style` include Hidden. - #[must_use] pub fn hidden(mut self) -> Self { + #[must_use] + pub fn hidden(mut self) -> Self { self.add(Styles::Hidden); self } /// Makes this `Style` include Strikethrough. - #[must_use] pub fn strikethrough(mut self) -> Self { + #[must_use] + pub fn strikethrough(mut self) -> Self { self.add(Styles::Strikethrough); self }