Files
llmx/codex-rs/tui/src/exec_command.rs
ae 9baa5c33da feat: update splash (#3631)
- Update splash styling.
- Add center truncation for long paths.
  (Uses new `center_truncate_path` utility.)
- Update the suggested commands.


## New splash
<img width="560" height="326" alt="image"
src="https://github.com/user-attachments/assets/b80d7075-f376-4019-a464-b96a78b0676d"
/>

## Example with truncation:
<img width="524" height="317" alt="image"
src="https://github.com/user-attachments/assets/b023c5cc-0bf0-4d21-9b98-bfea85546eda"
/>
2025-09-15 06:44:40 -07:00

54 lines
1.5 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
use std::path::Path;
use std::path::PathBuf;
use dirs::home_dir;
use shlex::try_join;
pub(crate) fn escape_command(command: &[String]) -> String {
try_join(command.iter().map(|s| s.as_str())).unwrap_or_else(|_| command.join(" "))
}
pub(crate) fn strip_bash_lc_and_escape(command: &[String]) -> String {
match command {
[first, second, third] if first == "bash" && second == "-lc" => third.clone(),
_ => escape_command(command),
}
}
/// If `path` is absolute and inside $HOME, return the part *after* the home
/// directory; otherwise, return the path as-is. Note if `path` is the homedir,
/// this will return and empty path.
pub(crate) fn relativize_to_home<P>(path: P) -> Option<PathBuf>
where
P: AsRef<Path>,
{
let path = path.as_ref();
if !path.is_absolute() {
// If the path is not absolute, we cant do anything with it.
return None;
}
let home_dir = home_dir()?;
let rel = path.strip_prefix(&home_dir).ok()?;
Some(rel.to_path_buf())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_escape_command() {
let args = vec!["foo".into(), "bar baz".into(), "weird&stuff".into()];
let cmdline = escape_command(&args);
assert_eq!(cmdline, "foo 'bar baz' 'weird&stuff'");
}
#[test]
fn test_strip_bash_lc_and_escape() {
let args = vec!["bash".into(), "-lc".into(), "echo hello".into()];
let cmdline = strip_bash_lc_and_escape(&args);
assert_eq!(cmdline, "echo hello");
}
}