term/spinner: Only handle signals on Unix

The `radicle-signals` crate only supports Unix, so using it prevents
`radicle-term` to build on Windows.

Of course, this means that non-Unix platforms will not support any
signal handling at all, but at least we can build.
This commit is contained in:
Lorenz Leutgeb 2025-07-14 16:38:58 +02:00
parent 92d77f9ec3
commit d46d36ecee
2 changed files with 17 additions and 10 deletions

View File

@ -15,7 +15,6 @@ default = ["git2"]
[dependencies] [dependencies]
anyhow = { workspace = true } anyhow = { workspace = true }
anstyle-query = "1.0.0" anstyle-query = "1.0.0"
crossbeam-channel = { workspace = true }
crossterm = "0.29.0" crossterm = "0.29.0"
inquire = { version = "0.7.4", default-features = false, features = ["crossterm", "editor"] } inquire = { version = "0.7.4", default-features = false, features = ["crossterm", "editor"] }
libc = { workspace = true } libc = { workspace = true }
@ -25,6 +24,9 @@ unicode-display-width = "0.3.0"
unicode-segmentation = "1.7.1" unicode-segmentation = "1.7.1"
zeroize = { workspace = true } zeroize = { workspace = true }
git2 = { workspace = true, features = ["vendored-libgit2"], optional = true } git2 = { workspace = true, features = ["vendored-libgit2"], optional = true }
[target.'cfg(unix)'.dependencies]
crossbeam-channel = { workspace = true }
radicle-signals = { workspace = true } radicle-signals = { workspace = true }
[dev-dependencies] [dev-dependencies]

View File

@ -3,11 +3,6 @@ use std::mem::ManuallyDrop;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::{fmt, io, thread, time}; use std::{fmt, io, thread, time};
use crossbeam_channel as chan;
use radicle_signals as signals;
use signals::Signal;
use crate::io::{ERROR_PREFIX, WARNING_PREFIX}; use crate::io::{ERROR_PREFIX, WARNING_PREFIX};
use crate::Paint; use crate::Paint;
@ -136,8 +131,13 @@ pub fn spinner_to(
) -> Spinner { ) -> Spinner {
let message = message.to_string(); let message = message.to_string();
let progress = Arc::new(Mutex::new(Progress::new(Paint::new(message)))); let progress = Arc::new(Mutex::new(Progress::new(Paint::new(message))));
let (sig_tx, sig_rx) = chan::unbounded();
let sig_result = signals::install(sig_tx); #[cfg(unix)]
let (sig_tx, sig_rx) = crossbeam_channel::unbounded();
#[cfg(unix)]
let sig_result = radicle_signals::install(sig_tx);
let handle = thread::Builder::new() let handle = thread::Builder::new()
.name(String::from("spinner")) .name(String::from("spinner"))
.spawn({ .spawn({
@ -151,9 +151,13 @@ pub fn spinner_to(
break; break;
}; };
// If were unable to install handles, skip signal processing entirely. // If were unable to install handles, skip signal processing entirely.
#[cfg(unix)]
if sig_result.is_ok() { if sig_result.is_ok() {
match sig_rx.try_recv() { match sig_rx.try_recv() {
Ok(sig) if sig == Signal::Interrupt || sig == Signal::Terminate => { Ok(sig)
if sig == radicle_signals::Signal::Interrupt
|| sig == radicle_signals::Signal::Terminate =>
{
write!(animation, "\r{CLEAR_UNTIL_NEWLINE}").ok(); write!(animation, "\r{CLEAR_UNTIL_NEWLINE}").ok();
writeln!( writeln!(
completion, completion,
@ -225,8 +229,9 @@ pub fn spinner_to(
write!(animation, "{}", crossterm::cursor::Show).ok(); write!(animation, "{}", crossterm::cursor::Show).ok();
#[cfg(unix)]
if sig_result.is_ok() { if sig_result.is_ok() {
let _ = signals::uninstall(); let _ = radicle_signals::uninstall();
} }
} }
}) })