From 92dc384823411596244f695ef7c15b2ce0aa7f70 Mon Sep 17 00:00:00 2001 From: Xithrius <15021300+Xithrius@users.noreply.github.com> Date: Sun, 18 Aug 2024 22:07:37 -0700 Subject: [PATCH] Fixing Windows `winapi` crash on run with `SetUnderlineColor` (#651) --- Cargo.toml | 18 +++- src/handlers/data.rs | 13 ++- src/ui/components/emote_picker.rs | 12 ++- src/utils/styles.rs | 151 ++++++++++-------------------- 4 files changed, 85 insertions(+), 109 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 745735e0..edba36d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,11 +14,6 @@ categories = ["command-line-utilities"] [dependencies] crossterm = "0.28.1" -tui = { package = "ratatui", version = "0.28.0", default-features = false, features = [ - "crossterm", - "serde", - "underline-color", -] } tokio = { version = "1.39.2", features = [ "rt", "macros", @@ -52,6 +47,19 @@ webbrowser = "1.0.1" memchr = "2.7.4" webp-animation = { version = "0.9.0", features = ["image"] } +[target.'cfg(not(windows))'.dependencies] +tui = { package = "ratatui", version = "0.28.0", default-features = false, features = [ + "crossterm", + "serde", + "underline-color", +] } + +[target.'cfg(windows)'.dependencies] +tui = { package = "ratatui", version = "0.28.0", default-features = false, features = [ + "crossterm", + "serde", +] } + [features] static-webp = ["webp-animation/static"] diff --git a/src/handlers/data.rs b/src/handlers/data.rs index c0286bd2..37af8349 100644 --- a/src/handlers/data.rs +++ b/src/handlers/data.rs @@ -339,9 +339,19 @@ impl MessageData { content: impl Into>, emotes: &mut &[(Color, Color)], ) -> Span<'s> { + #[allow(unused_variables)] if let Some(&(id, pid)) = emotes.first() { *emotes = &emotes[1..]; - Span::styled(content, Style::default().fg(id).underline_color(pid)) + + #[cfg(not(target_os = "windows"))] + { + Span::styled(content, Style::default().fg(id).underline_color(pid)) + } + + #[cfg(target_os = "windows")] + { + Span::styled(content, Style::default().fg(id)) + } } else { error!("Emote index >= emotes.len()"); Span::raw(content) @@ -655,6 +665,7 @@ impl<'conf> DataBuilder<'conf> { } #[cfg(test)] +#[cfg(not(target_os = "windows"))] mod tests { use super::*; use std::collections::BTreeMap; diff --git a/src/ui/components/emote_picker.rs b/src/ui/components/emote_picker.rs index c4435f98..a48c69dd 100644 --- a/src/ui/components/emote_picker.rs +++ b/src/ui/components/emote_picker.rs @@ -177,6 +177,14 @@ impl Component for EmotePickerWidget { let cols = (loaded_emote.width as f32 / cell_size.0).ceil() as u16; + #[cfg(not(target_os = "windows"))] + let underline_style = Style::default() + .fg(u32_to_color(loaded_emote.hash)) + .underline_color(u32_to_color(1)); + + #[cfg(target_os = "windows")] + let underline_style = { Style::default().fg(u32_to_color(loaded_emote.hash)) }; + let row = vec![ Span::raw(name[0..pos].to_owned()), Span::styled( @@ -187,9 +195,7 @@ impl Component for EmotePickerWidget { Span::raw(" - "), Span::styled( UnicodePlaceholder::new(cols as usize).string(), - Style::default() - .fg(u32_to_color(loaded_emote.hash)) - .underline_color(u32_to_color(1)), + underline_style, ), ]; diff --git a/src/utils/styles.rs b/src/utils/styles.rs index 0d222192..7f06fc6b 100644 --- a/src/utils/styles.rs +++ b/src/utils/styles.rs @@ -21,128 +21,79 @@ macro_rules! color { }; } -pub static BOLD_STYLE: Lazy