Skip to content

Commit

Permalink
fix: unnest task cmd output
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 18, 2024
1 parent d78313e commit bc747ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 7 additions & 0 deletions e2e/tasks/test_task_unnest
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ assert "mise run --output prefix c" "\
[c] c
[b] b
[a] a"

assert "mise run --no-timings --output prefix c 2>&1" '[c] $ echo c && mise run b
[c] c
[b] $ echo b && mise run a
[b] b
[a] $ echo a
[a] a'
19 changes: 11 additions & 8 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ impl Run {
"MISE_TASK_LEVEL".into(),
(*env::MISE_TASK_LEVEL + 1).to_string(),
);
if !self.timings {
env.insert("MISE_TASK_TIMINGS".to_string(), "0".to_string());
}
if let Some(cwd) = &*dirs::CWD {
env.insert("MISE_ORIGINAL_CWD".into(), cwd.display().to_string());
}
Expand Down Expand Up @@ -408,8 +411,8 @@ impl Run {
.bright()
.to_string();
if !self.quiet(Some(task)) {
let msg = format!("{prefix} {}", config.redact(cmd));
prefix_eprintln!(prefix, "{}", trunc(&msg));
let msg = trunc(prefix, config.redact(cmd).trim());
prefix_eprintln!(prefix, "{msg}")
}

if script.starts_with("#!") {
Expand Down Expand Up @@ -507,11 +510,10 @@ impl Run {
}

if !self.quiet(Some(task)) {
let cmd = format!("{} {}", display_path(file), args.join(" "));
let cmd = format!("{} {}", display_path(file), args.join(" ")).trim().to_string();
let cmd = style::ebold(format!("$ {cmd}")).bright().to_string();
let cmd = trunc(&format!("{prefix} {}", config.redact(cmd)));
// TODO: prefix_eprintln!("{cmd}");
eprintln!("{cmd}");
let cmd = trunc(prefix, config.redact(cmd).trim());
prefix_eprintln!(prefix, "{cmd}");
}

self.exec(file, &args, task, &env, prefix)
Expand Down Expand Up @@ -860,9 +862,10 @@ pub enum TaskOutput {
Silent,
}

fn trunc(msg: &str) -> String {
fn trunc(prefix: &str, msg: &str) -> String {
let prefix_len = console::measure_text_width(prefix);
let msg = msg.lines().next().unwrap_or_default();
console::truncate_str(msg, *env::TERM_WIDTH, "…").to_string()
console::truncate_str(msg, *env::TERM_WIDTH - prefix_len - 1, "…").to_string()
}

fn err_no_task(name: &str) -> Result<()> {
Expand Down

0 comments on commit bc747ba

Please sign in to comment.