Compare commits

..
2 changed files with 13 additions and 34 deletions

View file

@ -56,17 +56,8 @@ fn ellipsis() -> &'static str {
/// Cells, not chars: the message can carry a peer-supplied transport error, and /// 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. /// a CJK/emoji byte there must not push the alert into the next pane.
pub fn alert_line(msg: &str, width: u16) -> String { 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(); let mut text = msg.to_string();
if mode == ColorMode::None && !text.starts_with("! ") { if color_mode() == ColorMode::None && !text.starts_with("! ") {
text = format!("! {text}"); text = format!("! {text}");
} }
fit_cells(&text, width as usize) fit_cells(&text, width as usize)

View file

@ -833,7 +833,7 @@ async fn renders_a_queued_row_from_a_real_outbox_send() {
// Colour token set (card t_49b7c2b1) // 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}; use ratatui::style::{Color, Modifier};
#[test] #[test]
@ -910,24 +910,17 @@ fn tokens_for_is_deterministic_across_calls() {
#[test] #[test]
fn alert_line_prefixes_when_no_color() { fn alert_line_prefixes_when_no_color() {
// ColorMode::None (NO_COLOR) → alert_line prepends "! ". The mode is // NO_COLOR → ColorMode::None → alert_line prepends "! "
// injected rather than read from the process env: other tests in this let _guard = std::env::var_os("NO_COLOR");
// binary flip NO_COLOR concurrently, which made the env version flaky. unsafe { std::env::set_var("NO_COLOR", "1") };
let plain = alert_line_for_mode(ColorMode::None, "peer down", 80); let line = alert_line("peer down", 80);
assert!( assert!(line.starts_with("! "), "expected '! ' prefix in None mode: {line:?}");
plain.starts_with("! "), unsafe {
"expected '! ' prefix in None mode: {plain:?}" match _guard {
); Some(v) => std::env::set_var("NO_COLOR", v),
// The ornament belongs to the None path only; RGB keeps the message verbatim. None => std::env::remove_var("NO_COLOR"),
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"
);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -981,11 +974,6 @@ fn render_menu(w: u16, h: u16, st: &WalletMenuState) -> String {
#[test] #[test]
fn wallets_settings_menu_frame_shows_the_shipped_footer() { 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 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 // (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 // `footer_hints`; the fixture has to do the same or every menu frame in the