Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions shrs/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use shrs_core::{
builtin::Builtins,
dummy_child,
hooks::{BeforeCommandCtx, Hooks, JobExitCtx, StartupCtx},
Alias, Context, Env, ExitStatus, Jobs, Lang, Runtime, Shell, Signals, State, Theme,
Alias, Context, Env, Lang, Runtime, Shell, Signals, State, Theme,
};
use shrs_job::JobManager;
use shrs_lang::PosixLang;
Expand Down Expand Up @@ -101,7 +101,6 @@ impl ShellConfig {
alias: self.alias,
out: BufWriter::new(stdout()),
state: self.state,
jobs: Jobs::new(),
startup_time: Instant::now(),
};
let mut rt = Runtime {
Expand Down Expand Up @@ -178,14 +177,14 @@ fn run_shell(
}

// check up on running jobs
let mut exit_statuses = vec![];
ctx.jobs.retain(|status: ExitStatus| {
exit_statuses.push(status);
});

for status in exit_statuses.into_iter() {
sh.hooks
.run::<JobExitCtx>(sh, ctx, rt, JobExitCtx { status });
}
// let mut exit_statuses = vec![];
// ctx.jobs.retain(|status: ExitStatus| {
// exit_statuses.push(status);
// });

// for status in exit_statuses.into_iter() {
// sh.hooks
// .run::<JobExitCtx>(sh, ctx, rt, JobExitCtx { status });
// }
}
}
6 changes: 4 additions & 2 deletions shrs_core/src/builtin/jobs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
borrow::Borrow,
env,
path::{Path, PathBuf},
};
Expand All @@ -21,8 +22,9 @@ impl BuiltinCmd for JobsBuiltin {
rt: &mut Runtime,
args: &Vec<String>,
) -> anyhow::Result<BuiltinStatus> {
for (job_id, _) in ctx.jobs.iter() {
println!("{}", job_id);
let job_manager = sh.job_manager.borrow();
for job in job_manager.get_jobs() {
println!("{} {}", job.id(), job.display());
}

Ok(BuiltinStatus::success())
Expand Down
6 changes: 3 additions & 3 deletions shrs_core/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{

use crossterm::{style::Print, QueueableCommand};

use crate::{jobs::ExitStatus, Context, Runtime, Shell};
use crate::{Context, Runtime, Shell};

pub type HookFn<C: Clone> =
fn(sh: &Shell, sh_ctx: &mut Context, sh_rt: &mut Runtime, ctx: &C) -> anyhow::Result<()>;
Expand Down Expand Up @@ -111,7 +111,7 @@ pub fn change_dir_hook(
/// Context for [JobExit]
#[derive(Clone)]
pub struct JobExitCtx {
pub status: ExitStatus,
// pub status: ExitStatus,
}

/// Default [JobExitHook]
Expand All @@ -121,7 +121,7 @@ pub fn job_exit_hook(
sh_rt: &mut Runtime,
ctx: &JobExitCtx,
) -> anyhow::Result<()> {
println!("[exit +{}]", ctx.status.code());
// println!("[exit +{}]", ctx.status.code());
Ok(())
}

Expand Down
100 changes: 0 additions & 100 deletions shrs_core/src/jobs.rs

This file was deleted.

5 changes: 1 addition & 4 deletions shrs_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ mod state;
pub use state::State;

mod lang;
pub use lang::Lang;

mod jobs;
// TODO temp re-export anyhow
pub use anyhow;
pub use jobs::{ExitStatus, JobId, JobInfo, Jobs};
pub use lang::Lang;

/*
#[cfg(test)]
Expand Down
2 changes: 0 additions & 2 deletions shrs_core/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::{
builtin::Builtins,
env::Env,
hooks::{AfterCommandCtx, BeforeCommandCtx, Hooks, JobExitCtx, StartupCtx},
jobs::{ExitStatus, Jobs},
signal::Signals,
state::State,
theme::Theme,
Expand Down Expand Up @@ -57,7 +56,6 @@ pub struct Context {
/// Output stream
pub out: BufWriter<std::io::Stdout>,
pub state: State,
pub jobs: Jobs,
pub startup_time: Instant,
}

Expand Down
20 changes: 13 additions & 7 deletions shrs_lang/src/eval2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub fn run_job(
pgid: Option<u32>,
foreground: bool,
) -> anyhow::Result<()> {
if procs.is_empty() {
return Ok(());
}

let proc_group = ProcessGroup {
id: pgid,
processes: procs,
Expand All @@ -41,6 +45,7 @@ pub fn run_job(
pub fn eval_command(
job_manager: &mut JobManager,
cmd: &ast::Command,
pgid: Option<u32>,
stdin: Option<Stdin>,
stdout: Option<Output>,
) -> anyhow::Result<(Vec<Box<dyn Process>>, Option<u32>)> {
Expand All @@ -63,29 +68,30 @@ pub fn eval_command(
proc_stdin,
proc_stdout,
Output::Inherit,
None,
pgid,
)?;
Ok((vec![proc], pgid))
},
ast::Command::Pipeline(a_cmd, b_cmd) => {
let (mut a_procs, a_pgid) =
eval_command(job_manager, a_cmd, stdin, Some(Output::CreatePipe))?;
let (b_procs, b_pgid) = eval_command(
let (mut a_procs, pgid) =
eval_command(job_manager, a_cmd, pgid, stdin, Some(Output::CreatePipe))?;
let (b_procs, pgid) = eval_command(
job_manager,
b_cmd,
pgid,
a_procs.last_mut().unwrap().stdout(),
stdout,
)?;
a_procs.extend(b_procs);
Ok((a_procs, b_pgid))
Ok((a_procs, pgid))
},
ast::Command::AsyncList(a_cmd, b_cmd) => {
// TODO double check stdin and stdout
let (procs, pgid) = eval_command(job_manager, a_cmd, None, None)?;
let (procs, pgid) = eval_command(job_manager, a_cmd, pgid, None, None)?;
run_job(job_manager, procs, pgid, false)?;

if let Some(b_cmd) = b_cmd {
eval_command(job_manager, b_cmd, None, None)
eval_command(job_manager, b_cmd, pgid, None, None)
} else {
Ok((vec![], None))
}
Expand Down
3 changes: 2 additions & 1 deletion shrs_lang/src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ impl Lang for PosixLang {
println!("{:?}", cmd);

let mut job_manager = sh.job_manager.borrow_mut();
let (procs, pgid) = eval2::eval_command(&mut job_manager, &cmd, None, None)?;
job_manager.do_job_notification();
let (procs, pgid) = eval2::eval_command(&mut job_manager, &cmd, None, None, None)?;

run_job(&mut job_manager, procs, pgid, true)?;

Expand Down