diff --git a/src/tui.rs b/src/tui.rs index 1ffd94c..93f94f6 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -56,17 +56,8 @@ fn ellipsis() -> &'static str { /// Cells, not chars: the message can carry a peer-supplied transport error, and /// a CJK/emoji byte there must not push the alert into the next pane. pub fn alert_line(msg: &str, width: u16) -> String { - alert_line_for_mode(color_mode(), msg, width) -} - -/// [`alert_line`] with the colour mode supplied by the caller. -/// -/// Tests pin the `! ` ornament of the no-colour path through this entry point -/// rather than flipping `NO_COLOR`, which is process-global and mutated -/// concurrently by other tests in the same binary. -pub fn alert_line_for_mode(mode: ColorMode, msg: &str, width: u16) -> String { let mut text = msg.to_string(); - if mode == ColorMode::None && !text.starts_with("! ") { + if color_mode() == ColorMode::None && !text.starts_with("! ") { text = format!("! {text}"); } fit_cells(&text, width as usize) diff --git a/tests/tui_spec.rs b/tests/tui_spec.rs index 8e9a4c2..8a13603 100644 --- a/tests/tui_spec.rs +++ b/tests/tui_spec.rs @@ -833,7 +833,7 @@ async fn renders_a_queued_row_from_a_real_outbox_send() { // Colour token set (card t_49b7c2b1) // --------------------------------------------------------------------------- -use onionwire::tui::{ColorMode, alert_line_for_mode, tokens_for}; +use onionwire::tui::{ColorMode, tokens_for}; use ratatui::style::{Color, Modifier}; #[test] @@ -910,24 +910,17 @@ fn tokens_for_is_deterministic_across_calls() { #[test] fn alert_line_prefixes_when_no_color() { - // ColorMode::None (NO_COLOR) → alert_line prepends "! ". The mode is - // injected rather than read from the process env: other tests in this - // binary flip NO_COLOR concurrently, which made the env version flaky. - let plain = alert_line_for_mode(ColorMode::None, "peer down", 80); - assert!( - plain.starts_with("! "), - "expected '! ' prefix in None mode: {plain:?}" - ); - // The ornament belongs to the None path only; RGB keeps the message verbatim. - assert_eq!( - alert_line_for_mode(ColorMode::Rgb, "peer down", 80), - "peer down" - ); - // An alert that already carries the ornament is not double-prefixed. - assert_eq!( - alert_line_for_mode(ColorMode::None, "! peer down", 80), - "! peer down" - ); + // NO_COLOR → ColorMode::None → alert_line prepends "! " + let _guard = std::env::var_os("NO_COLOR"); + unsafe { std::env::set_var("NO_COLOR", "1") }; + let line = alert_line("peer down", 80); + assert!(line.starts_with("! "), "expected '! ' prefix in None mode: {line:?}"); + unsafe { + match _guard { + Some(v) => std::env::set_var("NO_COLOR", v), + None => std::env::remove_var("NO_COLOR"), + } + }; } // --------------------------------------------------------------------------- @@ -981,11 +974,6 @@ fn render_menu(w: u16, h: u16, st: &WalletMenuState) -> String { #[test] fn wallets_settings_menu_frame_shows_the_shipped_footer() { - // Both sides of the assertion read the process environment through - // `ascii_chrome()` / `color_mode()` (glyphs and alert ornaments), so this - // test must serialise with the other env-mutating tests in this binary. - let _guard = ASCII_ENV.lock().expect("ascii env lock"); - force_unicode_mode(); // The app renders this screen's one status line with `status_footer_phased` // (the chrome redesign put the Tor phase in it) and the hint from // `footer_hints`; the fixture has to do the same or every menu frame in the