From ab26166f96adee7f6989ae24b172fa66a575adf8 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Thu, 10 Sep 2026 18:19:39 +0800 Subject: [PATCH] fix(review): keep pane_procs's doc on pane_procs, round rtt before the unit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new `link_rtt` landed between `pane_procs`'s doc comment and `pane_procs` itself, so the comment about walking pane process trees documented the latency probe instead. `format_rtt` also compared the unrounded milliseconds against 1000, so a 999.6 ms round trip printed as "1000 ms" — a millisecond reading past the range the millisecond branch exists to cover. Round first, then pick the unit. Claude-Session: https://claude.ai/code/session_01E4EPKzHg1fm9HMmHkUYpER --- crates/tty7-core/src/host/remote.rs | 8 ++++---- src/ui/right_panel.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/tty7-core/src/host/remote.rs b/crates/tty7-core/src/host/remote.rs index e3803b3f..c90896f4 100644 --- a/crates/tty7-core/src/host/remote.rs +++ b/crates/tty7-core/src/host/remote.rs @@ -253,10 +253,6 @@ impl Host for RemoteHost { }) } - /// The peer owns these panes' PTYs, so it is the one that can walk their - /// process trees. A peer that does not announce the feature is not asked: - /// it would answer `Err` and the caller cannot tell that apart from a pane - /// serving nothing. fn link_rtt(&self) -> Option { // A ping of our own rather than whatever the keepalive last left // behind: that one only fires on an idle link, and a link being polled @@ -273,6 +269,10 @@ impl Host for RemoteHost { self.client.last_rtt() } + /// The peer owns these panes' PTYs, so it is the one that can walk their + /// process trees. A peer that does not announce the feature is not asked: + /// it would answer `Err` and the caller cannot tell that apart from a pane + /// serving nothing. fn pane_procs(&self, pane_id: u64) -> Option { if !self .peer() diff --git a/src/ui/right_panel.rs b/src/ui/right_panel.rs index 3521a53f..364621f4 100644 --- a/src/ui/right_panel.rs +++ b/src/ui/right_panel.rs @@ -278,8 +278,11 @@ fn format_rtt(rtt: std::time::Duration) -> String { // "0 ms" would read as a failed measurement rather than a fast one. return "<1 ms".to_string(); } - if ms < 1000. { - return format!("{} ms", ms.round() as u64); + // Rounded before the comparison, so 999.6 ms is not shown as "1000 ms" — + // a millisecond reading that has run past the unit's own range. + let rounded = ms.round() as u64; + if rounded < 1000 { + return format!("{rounded} ms"); } format!("{:.1} s", rtt.as_secs_f64()) } @@ -2006,6 +2009,9 @@ mod tests { assert_eq!(format_rtt(Duration::from_millis(1)), "1 ms"); assert_eq!(format_rtt(Duration::from_micros(23_400)), "23 ms"); assert_eq!(format_rtt(Duration::from_millis(999)), "999 ms"); + // Rounding up out of the millisecond's own range hands the number to + // the unit above rather than printing a four-digit millisecond. + assert_eq!(format_rtt(Duration::from_micros(999_600)), "1.0 s"); // Past a second the millisecond has stopped carrying information, and // the second is the unit anyone would say the number in. assert_eq!(format_rtt(Duration::from_millis(1_450)), "1.4 s");