cicada/builtins/
jobs.rs

1use crate::builtins::utils::print_stdout_with_capture;
2use crate::jobc;
3use crate::shell::Shell;
4use crate::types::{Command, CommandLine, CommandResult};
5
6pub fn run(sh: &mut Shell, cl: &CommandLine, cmd: &Command, capture: bool) -> CommandResult {
7    let mut cr = CommandResult::new();
8    if sh.jobs.is_empty() {
9        return cr;
10    }
11
12    // update status of jobs if any
13    jobc::try_wait_bg_jobs(sh, false, false);
14
15    let mut lines = Vec::new();
16    let jobs = sh.jobs.clone();
17    let no_trim = cmd.tokens.len() >= 2 && cmd.tokens[1].1 == "-f";
18    for (_i, job) in jobs.iter() {
19        let line = jobc::get_job_line(job, !no_trim);
20        lines.push(line);
21    }
22    let buffer = lines.join("\n");
23
24    print_stdout_with_capture(&buffer, &mut cr, cl, cmd, capture);
25    cr
26}