diff --git a/docs/cli/run.md b/docs/cli/run.md index 97d0bede9f..c8107b74ae 100644 --- a/docs/cli/run.md +++ b/docs/cli/run.md @@ -96,7 +96,7 @@ Change how tasks information is output when running tasks - `prefix` - Print stdout/stderr by line, prefixed with the task's label - `interleave` - Print directly to stdout/stderr instead of by line - `replacing` - Stdout is replaced each time, stderr is printed as is -- `lengthy` - Only show stdout lines if they are displayed for more than 1 second +- `timed` - Only show stdout lines if they are displayed for more than 1 second - `keep-order` - Print stdout/stderr by line, prefixed with the task's label, but keep the order of the output - `quiet` - Don't show extra output - `silent` - Don't show any output including stdout and stderr from the task except for errors diff --git a/docs/cli/tasks/run.md b/docs/cli/tasks/run.md index a344c9d5fe..3ac1582fb7 100644 --- a/docs/cli/tasks/run.md +++ b/docs/cli/tasks/run.md @@ -110,7 +110,7 @@ Change how tasks information is output when running tasks - `prefix` - Print stdout/stderr by line, prefixed with the task's label - `interleave` - Print directly to stdout/stderr instead of by line - `replacing` - Stdout is replaced each time, stderr is printed as is -- `lengthy` - Only show stdout lines if they are displayed for more than 1 second +- `timed` - Only show stdout lines if they are displayed for more than 1 second - `keep-order` - Print stdout/stderr by line, prefixed with the task's label, but keep the order of the output - `quiet` - Don't show extra output - `silent` - Don't show any output including stdout and stderr from the task except for errors diff --git a/mise.usage.kdl b/mise.usage.kdl index 9bc39a9d98..2912b7962d 100644 --- a/mise.usage.kdl +++ b/mise.usage.kdl @@ -1088,7 +1088,7 @@ The name of the script will be the name of the tasks. flag "-q --quiet" help="Don't show extra output" flag "-S --silent" help="Don't show any output except for errors" flag "-o --output" help="Change how tasks information is output when running tasks" { - long_help "Change how tasks information is output when running tasks\n\n- `prefix` - Print stdout/stderr by line, prefixed with the task's label\n- `interleave` - Print directly to stdout/stderr instead of by line\n- `replacing` - Stdout is replaced each time, stderr is printed as is\n- `lengthy` - Only show stdout lines if they are displayed for more than 1 second\n- `keep-order` - Print stdout/stderr by line, prefixed with the task's label, but keep the order of the output\n- `quiet` - Don't show extra output\n- `silent` - Don't show any output including stdout and stderr from the task except for errors" + long_help "Change how tasks information is output when running tasks\n\n- `prefix` - Print stdout/stderr by line, prefixed with the task's label\n- `interleave` - Print directly to stdout/stderr instead of by line\n- `replacing` - Stdout is replaced each time, stderr is printed as is\n- `timed` - Only show stdout lines if they are displayed for more than 1 second\n- `keep-order` - Print stdout/stderr by line, prefixed with the task's label, but keep the order of the output\n- `quiet` - Don't show extra output\n- `silent` - Don't show any output including stdout and stderr from the task except for errors" arg "" } mount run="mise tasks --usage" @@ -1530,7 +1530,7 @@ The name of the script will be the name of the tasks. flag "-q --quiet" help="Don't show extra output" flag "-S --silent" help="Don't show any output except for errors" flag "-o --output" help="Change how tasks information is output when running tasks" { - long_help "Change how tasks information is output when running tasks\n\n- `prefix` - Print stdout/stderr by line, prefixed with the task's label\n- `interleave` - Print directly to stdout/stderr instead of by line\n- `replacing` - Stdout is replaced each time, stderr is printed as is\n- `lengthy` - Only show stdout lines if they are displayed for more than 1 second\n- `keep-order` - Print stdout/stderr by line, prefixed with the task's label, but keep the order of the output\n- `quiet` - Don't show extra output\n- `silent` - Don't show any output including stdout and stderr from the task except for errors" + long_help "Change how tasks information is output when running tasks\n\n- `prefix` - Print stdout/stderr by line, prefixed with the task's label\n- `interleave` - Print directly to stdout/stderr instead of by line\n- `replacing` - Stdout is replaced each time, stderr is printed as is\n- `timed` - Only show stdout lines if they are displayed for more than 1 second\n- `keep-order` - Print stdout/stderr by line, prefixed with the task's label, but keep the order of the output\n- `quiet` - Don't show extra output\n- `silent` - Don't show any output including stdout and stderr from the task except for errors" arg "" } arg "[TASK]" help="Tasks to run\nCan specify multiple tasks by separating with `:::`\ne.g.: mise run task1 arg1 arg2 ::: task2 arg1 arg2" required=false default="default" diff --git a/schema/mise.json b/schema/mise.json index 3164afdd35..788d87dabe 100644 --- a/schema/mise.json +++ b/schema/mise.json @@ -839,7 +839,15 @@ "task_output": { "description": "Change output style when executing tasks.", "type": "string", - "enum": ["prefix", "interleave", "keep-order", "quiet", "silent"] + "enum": [ + "prefix", + "interleave", + "keep-order", + "replacing", + "timed", + "quiet", + "silent" + ] }, "task_run_auto_install": { "default": true, diff --git a/settings.toml b/settings.toml index 7ecba0d03c..e15cb19ad0 100644 --- a/settings.toml +++ b/settings.toml @@ -977,6 +977,14 @@ enum = [ "keep-order", "print output from tasks in the order they are defined" ], + [ + "replacing", + "replace stdout each time a line is printed-this uses similar logic as `mise install`" + ], + [ + "timed", + "only show stdout lines that take longer than 1s to complete" + ], [ "quiet", "print only stdout/stderr from tasks and nothing from mise" diff --git a/src/cli/mod.rs b/src/cli/mod.rs index e1dd8c0a4b..f00e8d3a5f 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -390,6 +390,7 @@ impl Cli { tool: Default::default(), keep_order_output: Default::default(), task_prs: Default::default(), + timed_outputs: Default::default(), })); } else if let Some(cmd) = external::COMMANDS.get(&task) { external::execute( diff --git a/src/cli/run.rs b/src/cli/run.rs index 134d9bd9f0..229ab8a249 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -2,11 +2,11 @@ use std::collections::BTreeMap; use std::io::Write; use std::iter::once; use std::ops::Deref; -use std::panic; use std::path::{Path, PathBuf}; use std::process::Stdio; use std::sync::{Arc, Mutex}; -use std::time::SystemTime; +use std::time::{Duration, SystemTime}; +use std::{panic, thread}; use super::args::ToolArg; use crate::cli::Cli; @@ -176,7 +176,7 @@ pub struct Run { /// - `prefix` - Print stdout/stderr by line, prefixed with the task's label /// - `interleave` - Print directly to stdout/stderr instead of by line /// - `replacing` - Stdout is replaced each time, stderr is printed as is - /// - `lengthy` - Only show stdout lines if they are displayed for more than 1 second + /// - `timed` - Only show stdout lines if they are displayed for more than 1 second /// - `keep-order` - Print stdout/stderr by line, prefixed with the task's label, but keep the order of the output /// - `quiet` - Don't show extra output /// - `silent` - Don't show any output including stdout and stderr from the task except for errors @@ -191,6 +191,9 @@ pub struct Run { #[clap(skip)] pub task_prs: IndexMap>>, + + #[clap(skip)] + pub timed_outputs: Arc>>, } type KeepOrderOutputs = (Vec<(String, String)>, Vec<(String, String)>); @@ -232,6 +235,27 @@ impl Run { ctrlc::exit_on_ctrl_c(false); + if self.output(None) == TaskOutput::Timed { + let timed_outputs = self.timed_outputs.clone(); + thread::spawn(move || loop { + { + let mut outputs = timed_outputs.lock().unwrap(); + for (prefix, out) in outputs.clone() { + let (time, line) = out; + if time.elapsed().unwrap().as_secs() >= 1 { + if console::colors_enabled() { + prefix_println!(prefix, "{line}\x1b[0m"); + } else { + prefix_println!(prefix, "{line}"); + } + outputs.shift_remove(&prefix); + } + } + } + thread::sleep(Duration::from_millis(100)); + }); + } + self.fetch_tasks(&mut tasks)?; let tasks = Deps::new(tasks)?; for task in tasks.all() { @@ -249,7 +273,6 @@ impl Run { } _ => {} } - if self.output(Some(task)) == TaskOutput::KeepOrder {} } let num_tasks = tasks.all().count(); @@ -647,6 +670,22 @@ impl Run { let pr = self.task_prs.get(task).unwrap().clone(); cmd = cmd.with_pr_arc(pr); } + TaskOutput::Timed => { + let timed_outputs = self.timed_outputs.clone(); + cmd = cmd.with_on_stdout(move |line| { + timed_outputs + .lock() + .unwrap() + .insert(prefix.to_string(), (SystemTime::now(), line)); + }); + cmd = cmd.with_on_stderr(|line| { + if console::colors_enabled() { + self.eprint(task, prefix, &format!("{line}\x1b[0m")); + } else { + self.eprint(task, prefix, &line); + } + }); + } TaskOutput::Silent => { cmd = cmd.stdout(Stdio::null()).stderr(Stdio::null()); } @@ -960,6 +999,7 @@ pub enum TaskOutput { #[default] Prefix, Replacing, + Timed, Quiet, Silent, } diff --git a/tasks.toml b/tasks.toml index ceb03560ec..ed703d45d0 100644 --- a/tasks.toml +++ b/tasks.toml @@ -135,5 +135,5 @@ run = "cargo install --path . --debug" [xxx] hide = true tools = { gh = "2.60.0" } -run = "echo {{arg(name='greeting')}}" +run = "echo {{arg(name='greeting')}}; sleep 2; echo 2; sleep 2; echo 3; sleep 0.4; echo 4; sleep 1" description = "a task for testing"