diff --git a/tty-fwd/src/api_server.rs b/tty-fwd/src/api_server.rs index 239d3de5..8fd46a3f 100644 --- a/tty-fwd/src/api_server.rs +++ b/tty-fwd/src/api_server.rs @@ -681,7 +681,10 @@ fn handle_session_snapshot(control_path: &Path, path: &str) -> Response let original_lines = content.lines().count(); let optimized_lines = optimized_content.lines().count(); let reduction = if original_lines > 0 { - (original_lines - optimized_lines) as f64 / original_lines as f64 * 100.0 + #[allow(clippy::cast_precision_loss)] + { + (original_lines - optimized_lines) as f64 / original_lines as f64 * 100.0 + } } else { 0.0 }; @@ -716,7 +719,7 @@ fn handle_session_snapshot(control_path: &Path, path: &str) -> Response } fn optimize_snapshot_content(content: &str) -> String { - let lines: Vec<&str> = content.trim().split('\n').collect(); + let lines: Vec<&str> = content.lines().collect(); let mut header_line: Option<&str> = None; let mut all_events: Vec<&str> = Vec::new(); @@ -1177,11 +1180,17 @@ fn handle_multi_stream(control_path: &Path, req: &mut HttpRequest) { }; if let Err(e) = watcher.watch(&control_path_clone, RecursiveMode::NonRecursive) { - println!("Failed to watch control directory {control_path_clone:?}: {e}"); + println!( + "Failed to watch control directory {}: {e}", + control_path_clone.display() + ); return; } - println!("Session discovery thread started, watching {control_path_clone:?}"); + println!( + "Session discovery thread started, watching {}", + control_path_clone.display() + ); // Also discover existing sessions at startup if let Ok(sessions) = sessions::list_sessions(&control_path_clone) { @@ -1313,7 +1322,8 @@ fn handle_multi_stream(control_path: &Path, req: &mut HttpRequest) { if let Err(e) = watcher.watch(parent_dir, RecursiveMode::NonRecursive) { println!( - "Failed to watch directory {parent_dir:?} for session {session_id_clone}: {e}" + "Failed to watch directory {} for session {session_id_clone}: {e}", + parent_dir.display() ); return; } diff --git a/tty-fwd/src/main.rs b/tty-fwd/src/main.rs index aae06e39..e3493c98 100644 --- a/tty-fwd/src/main.rs +++ b/tty-fwd/src/main.rs @@ -194,7 +194,7 @@ fn main() -> Result<(), anyhow::Error> { // Handle serve command if let Some(addr) = serve_address { // Setup signal handler to update session statuses on shutdown - crate::term_socket::setup_shutdown_handler()?; + crate::term_socket::setup_shutdown_handler(); ctrlc::set_handler(move || { println!("Ctrl-C received, updating session statuses and exiting..."); diff --git a/tty-fwd/src/protocol.rs b/tty-fwd/src/protocol.rs index db8ec49e..6dee96a0 100644 --- a/tty-fwd/src/protocol.rs +++ b/tty-fwd/src/protocol.rs @@ -352,8 +352,8 @@ impl StreamWriter { // Skip parameter and intermediate characters while pos < buf.len() { match buf[pos] { - 0x30..=0x3F => pos += 1, // Parameter characters 0-9 : ; < = > ? - 0x20..=0x2F => pos += 1, // Intermediate characters (space) ! " # $ % & ' ( ) * + , - . / + // Parameter characters 0-9 : ; < = > ? and Intermediate characters + 0x20..=0x3F => pos += 1, 0x40..=0x7E => return Some(pos + 1), // Final character @ A-Z [ \ ] ^ _ ` a-z { | } ~ _ => return Some(pos), // Invalid sequence, stop here } @@ -377,8 +377,6 @@ impl StreamWriter { } // Simple two-character sequences: ESC letter - 0x40..=0x7E => Some(2), - // Other escape sequences - assume two characters for now _ => Some(2), } diff --git a/tty-fwd/src/term_socket.rs b/tty-fwd/src/term_socket.rs index 3be170ce..e20e3daf 100644 --- a/tty-fwd/src/term_socket.rs +++ b/tty-fwd/src/term_socket.rs @@ -11,8 +11,6 @@ use std::ffi::CString; use std::io::{Read, Write}; use std::os::unix::io::{AsRawFd, RawFd}; use std::os::unix::net::UnixStream; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; use uuid::Uuid; /// Spawn a terminal session with PTY fallback @@ -157,11 +155,11 @@ fn spawn_via_pty(command: &[String], working_dir: Option<&str>) -> Result) -> Result { eprintln!("PTY closed (EOF), updating session status"); // Update session status to exited - let session_json_path = format!("{}/session.json", session_dir); + let session_json_path = format!("{session_dir}/session.json"); if let Ok(content) = std::fs::read_to_string(&session_json_path) { if let Ok(mut session_info) = serde_json::from_str::(&content) @@ -457,7 +455,6 @@ fn handle_stdin_to_pty(master_fd: RawFd, stdin_path: &str) -> Result<()> { Ok(0) => { // No data available, sleep briefly to avoid busy waiting std::thread::sleep(std::time::Duration::from_millis(10)); - continue; } Ok(n) => { // Write to PTY master using libc::write @@ -471,7 +468,6 @@ fn handle_stdin_to_pty(master_fd: RawFd, stdin_path: &str) -> Result<()> { Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => { // No data available, sleep briefly std::thread::sleep(std::time::Duration::from_millis(10)); - continue; } Err(e) => { eprintln!("Error reading from stdin FIFO: {e}"); @@ -530,23 +526,16 @@ pub fn update_all_sessions_to_exited() -> Result<()> { } /// Setup signal handler to cleanup sessions on shutdown -pub fn setup_shutdown_handler() -> Result<()> { - let shutdown = Arc::new(AtomicBool::new(false)); - let shutdown_clone = shutdown.clone(); - +pub fn setup_shutdown_handler() { std::thread::spawn(move || { let mut signals = - Signals::new(&[SIGTERM, SIGINT]).expect("Failed to create signals iterator"); + Signals::new([SIGTERM, SIGINT]).expect("Failed to create signals iterator"); - for sig in signals.forever() { - eprintln!("Received signal {:?}, updating session statuses...", sig); + if let Some(sig) = signals.forever().next() { + eprintln!("Received signal {sig:?}, updating session statuses..."); if let Err(e) = update_all_sessions_to_exited() { - eprintln!("Failed to update session statuses: {}", e); + eprintln!("Failed to update session statuses: {e}"); } - shutdown_clone.store(true, Ordering::Relaxed); - break; } }); - - Ok(()) }