Skip to main content

aft_base/
shell_format.rs

1//! Stateless text primitives shared by shell persistence and reply renderers.
2
3/// Port of `packages/aft-bridge/src/bash-format.ts` `formatSeconds` (lines 3-6).
4pub fn format_seconds(ms: u64) -> String {
5    let mut seconds = format!("{:.1}", ms as f64 / 1000.0);
6    if seconds.ends_with(".0") {
7        seconds.truncate(seconds.len() - 2);
8    }
9    format!("{seconds}s")
10}
11
12/// A wait limit in words: whole minutes as minutes, anything else in seconds.
13pub fn format_wait_limit(ms: u64) -> String {
14    match ms {
15        60_000 => "1 minute".to_string(),
16        ms if ms > 0 && ms % 60_000 == 0 => format!("{} minutes", ms / 60_000),
17        ms => format_seconds(ms),
18    }
19}
20
21pub fn append_trailing_line(text: &mut String, line: &str) {
22    if !text.is_empty() {
23        text.push_str(if text.ends_with('\n') { "\n" } else { "\n\n" });
24    }
25    text.push_str(line);
26}
27
28/// Schema lookups are AFT-added trailers, not command output. Both terminal
29/// snapshots and completion previews call this after their output size caps.
30#[cfg(unix)]
31pub fn append_db_schema_hint(text: &mut String, hint: &str) {
32    append_trailing_line(text, hint);
33}