diff options
Diffstat (limited to '')
| -rw-r--r-- | src/client/ui.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/client/ui.rs b/src/client/ui.rs index 493f660..11cedc7 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs | |||
| @@ -257,6 +257,23 @@ pub fn input_cursor_column(prompt_len: usize, input_len: usize) -> u16 { | |||
| 257 | .min(u16::MAX as usize) as u16 | 257 | .min(u16::MAX as usize) as u16 |
| 258 | } | 258 | } |
| 259 | 259 | ||
| 260 | /// Number of terminal rows a block of logical lines occupies after wrapping. | ||
| 261 | /// Empty lines still occupy one row. | ||
| 262 | pub fn visual_line_count(lines: &[String], width: usize) -> usize { | ||
| 263 | let width = width.max(1); | ||
| 264 | lines | ||
| 265 | .iter() | ||
| 266 | .map(|line| { | ||
| 267 | let columns = display_width(line); | ||
| 268 | if columns == 0 { | ||
| 269 | 1 | ||
| 270 | } else { | ||
| 271 | columns.div_ceil(width) | ||
| 272 | } | ||
| 273 | }) | ||
| 274 | .sum() | ||
| 275 | } | ||
| 276 | |||
| 260 | /// Format a ping round-trip time with one decimal place. | 277 | /// Format a ping round-trip time with one decimal place. |
| 261 | pub fn format_pong(elapsed: std::time::Duration) -> String { | 278 | pub fn format_pong(elapsed: std::time::Duration) -> String { |
| 262 | format!("Pong ({:.1}ms)", elapsed.as_secs_f64() * 1000.0) | 279 | format!("Pong ({:.1}ms)", elapsed.as_secs_f64() * 1000.0) |
