diff --git a/src/ui/connection_table.rs b/src/ui/connection_table.rs index 6e9c7f5..51f5f7d 100644 --- a/src/ui/connection_table.rs +++ b/src/ui/connection_table.rs @@ -16,6 +16,8 @@ //! ellipsis only happens as a last resort at very narrow widths, after //! column hiding has already done its job. +use std::borrow::Cow; + use ratatui::layout::Constraint; use ratatui::style::{Color, Modifier, Style}; use ratatui::text::{Line, Span}; @@ -197,13 +199,14 @@ fn process_text(conn: &Connection) -> String { } /// Untruncated Service cell text: service name or port number. -fn service_text(conn: &Connection, ui_state: &UIState) -> String { +fn service_text<'a>(conn: &'a Connection, ui_state: &UIState) -> Cow<'a, str> { if ui_state.show_port_numbers { - conn.remote_addr.port().to_string() + Cow::Owned(conn.remote_addr.port().to_string()) } else { - conn.service_name - .clone() - .unwrap_or_else(|| NONE_PLACEHOLDER.to_string()) + match conn.service_name.as_deref() { + Some(name) => Cow::Borrowed(name), + None => Cow::Borrowed(NONE_PLACEHOLDER), + } } } @@ -336,7 +339,7 @@ fn staleness_style(conn: &Connection) -> (Option