From 9f74300c7ad9142145a56cf8f19fb5b9d616eb61 Mon Sep 17 00:00:00 2001 From: michel Date: Sun, 19 Jul 2026 21:22:38 +0200 Subject: [PATCH] fix(tui): stop raw prints from corrupting the TUI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Log lines were painting over the alternate-screen TUI because some messages bypassed the buffered logger and wrote straight to the terminal: - a live println! in GetPeerAddressHandler fired on every peer-address lookup (i.e. constantly while browsing/downloading) — routed to the buffered debug! logger. - the TUI's error handlers used eprintln! in the render loop and in background search/download worker threads — routed to the buffered warn! logger so failures no longer smear the screen. The logger already defers to a buffer while the TUI holds the screen; the fix is simply to go through it instead of print!/eprintln!. --- .../src/message/server/get_peer_address.rs | 2 +- soulseek-rs/src/ui/downloads.rs | 4 +++- soulseek-rs/src/ui/main_tui.rs | 21 +++++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/soulseek-rs-lib/src/message/server/get_peer_address.rs b/soulseek-rs-lib/src/message/server/get_peer_address.rs index d5b28ee..426bfa0 100644 --- a/soulseek-rs-lib/src/message/server/get_peer_address.rs +++ b/soulseek-rs-lib/src/message/server/get_peer_address.rs @@ -22,7 +22,7 @@ impl MessageHandler for GetPeerAddressHandler { let port = message.read_int32(); let obfuscation_type = message.read_int32(); let obfuscated_port = message.read_int32() as u16; - println!("GetPeerAddressHandler: {username:?}"); // Debug print + crate::debug!("GetPeerAddressHandler: {username:?}"); sender .send(ServerMessage::GetPeerAddressResponse { diff --git a/soulseek-rs/src/ui/downloads.rs b/soulseek-rs/src/ui/downloads.rs index 3b9dbe5..38887e5 100644 --- a/soulseek-rs/src/ui/downloads.rs +++ b/soulseek-rs/src/ui/downloads.rs @@ -501,7 +501,9 @@ pub fn show_multi_download_progress( let _ = tx.send((download, receiver)); } Err(e) => { - eprintln!("Failed to start download for {filename}: {e}"); + soulseek_rs::warn!( + "Failed to start download for {filename}: {e}" + ); } } } diff --git a/soulseek-rs/src/ui/main_tui.rs b/soulseek-rs/src/ui/main_tui.rs index 0f63b46..29c2eea 100644 --- a/soulseek-rs/src/ui/main_tui.rs +++ b/soulseek-rs/src/ui/main_tui.rs @@ -771,7 +771,9 @@ impl MainTui { let _ = sender.send((download, rx)); } Err(e) => { - eprintln!("Failed to queue download {path}: {e}"); + soulseek_rs::warn!( + "Failed to queue download {path}: {e}" + ); } } } @@ -954,7 +956,7 @@ impl MainTui { if let Some(name) = self.state.rooms.selected_room_name() { let newly_opened = self.state.rooms.focus_or_open(&name); if newly_opened && let Err(e) = self.client.join_room(&name) { - eprintln!("Failed to join {name}: {e}"); + soulseek_rs::warn!("Failed to join {name}: {e}"); } } } @@ -964,7 +966,7 @@ impl MainTui { if let Some(name) = self.state.rooms.close_active() && let Err(e) = self.client.leave_room(&name) { - eprintln!("Failed to leave {name}: {e}"); + soulseek_rs::warn!("Failed to leave {name}: {e}"); } } @@ -982,7 +984,7 @@ impl MainTui { } }; if let Err(e) = self.client.say_in_room(&room, &text) { - eprintln!("Failed to say in {room}: {e}"); + soulseek_rs::warn!("Failed to say in {room}: {e}"); } if let Some(room) = self.state.rooms.open.get_mut(active) { room.input.clear(); @@ -1331,7 +1333,7 @@ impl MainTui { Ok((download, rx)) => { let _ = sender.send((download, rx)); } - Err(e) => eprintln!("Failed to retry {filename}: {e}"), + Err(e) => soulseek_rs::warn!("Failed to retry {filename}: {e}"), } }); } @@ -1636,7 +1638,7 @@ impl MainTui { peer: recipient.to_string(), text: text.to_string(), }), - Err(e) => eprintln!("Failed to send message: {e}"), + Err(e) => soulseek_rs::warn!("Failed to send message: {e}"), } } @@ -1681,7 +1683,7 @@ impl MainTui { // Results will be polled in update_search_results } Err(e) => { - eprintln!("Search failed: {e}"); + soulseek_rs::warn!("Search failed: {e}"); } } }); @@ -1794,9 +1796,10 @@ impl MainTui { let _ = sender.send((download, rx)); } Err(e) => { - eprintln!( + soulseek_rs::warn!( "Failed to start download for {}: {}", - file.filename, e + file.filename, + e ); } }