Skip to main content

romm_cli/tui/
utils.rs

1use std::process::Command;
2
3/// Truncate a string to `max` chars, appending "…" if trimmed.
4pub fn truncate(s: &str, max: usize) -> String {
5    crate::core::utils::truncate(s, max)
6}
7
8// ---------------------------------------------------------------------------
9// OS helpers
10// ---------------------------------------------------------------------------
11
12/// Open a URL in the system default browser.
13pub fn open_in_browser(url: &str) -> std::io::Result<std::process::Child> {
14    let mut cmd = if cfg!(target_os = "windows") {
15        let mut c = Command::new("cmd");
16        c.args(["/C", "start", "", url]);
17        c
18    } else if cfg!(target_os = "macos") {
19        Command::new("open")
20    } else {
21        Command::new("xdg-open")
22    };
23
24    if !cfg!(target_os = "windows") {
25        cmd.arg(url);
26    }
27    cmd.spawn()
28}