summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/event.rs31
-rw-r--r--src/pipeline/mod.rs16
-rw-r--r--src/state/history/mod.rs13
-rw-r--r--src/state/mod.rs4
4 files changed, 19 insertions, 45 deletions
diff --git a/src/event.rs b/src/event.rs
index 771d69b..0343cdb 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -1,34 +1,13 @@
-#[derive(Debug, serde::Serialize, serde::Deserialize)]
+#[derive(Debug)]
pub enum Event {
- #[serde(
- serialize_with = "serialize_key",
- deserialize_with = "deserialize_key"
- )]
Key(textmode::Key),
Resize((u16, u16)),
PtyOutput,
PtyClose,
ChildSuspend(usize),
- PipelineExit(crate::env::Env),
ClockTimer,
}
-#[allow(clippy::trivially_copy_pass_by_ref, clippy::needless_pass_by_value)]
-fn serialize_key<S>(_key: &textmode::Key, _s: S) -> Result<S::Ok, S::Error>
-where
- S: serde::Serializer,
-{
- todo!()
-}
-
-#[allow(clippy::trivially_copy_pass_by_ref, clippy::needless_pass_by_value)]
-fn deserialize_key<'de, D>(_d: D) -> Result<textmode::Key, D::Error>
-where
- D: serde::Deserializer<'de>,
-{
- todo!()
-}
-
pub struct Reader {
pending: async_std::sync::Mutex<Pending>,
cvar: async_std::sync::Condvar,
@@ -78,7 +57,6 @@ struct Pending {
pty_output: bool,
pty_close: bool,
child_suspend: std::collections::VecDeque<usize>,
- pipeline_exit: std::collections::VecDeque<crate::env::Env>,
clock_timer: bool,
done: bool,
}
@@ -95,7 +73,6 @@ impl Pending {
|| self.pty_output
|| self.pty_close
|| !self.child_suspend.is_empty()
- || !self.pipeline_exit.is_empty()
|| self.clock_timer
}
@@ -116,9 +93,6 @@ impl Pending {
if let Some(idx) = self.child_suspend.pop_front() {
return Some(Event::ChildSuspend(idx));
}
- if let Some(env) = self.pipeline_exit.pop_front() {
- return Some(Event::PipelineExit(env));
- }
if self.clock_timer {
self.clock_timer = false;
return Some(Event::ClockTimer);
@@ -142,9 +116,6 @@ impl Pending {
Some(Event::ChildSuspend(idx)) => {
self.child_suspend.push_back(idx);
}
- Some(Event::PipelineExit(env)) => {
- self.pipeline_exit.push_back(env);
- }
Some(Event::ClockTimer) => self.clock_timer = true,
None => self.done = true,
}
diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs
index fd7d569..6e24bb5 100644
--- a/src/pipeline/mod.rs
+++ b/src/pipeline/mod.rs
@@ -6,6 +6,12 @@ use std::os::unix::process::ExitStatusExt as _;
const PID0: nix::unistd::Pid = nix::unistd::Pid::from_raw(0);
+#[derive(Debug, serde::Serialize, serde::Deserialize)]
+pub enum Event {
+ Suspend(usize),
+ Exit(crate::env::Env),
+}
+
mod command;
pub use command::{Child, Command};
@@ -15,7 +21,7 @@ pub async fn run() -> anyhow::Result<i32> {
let status = *env.latest_status();
let pwd = std::env::current_dir()?;
env.set_current_dir(pwd);
- write_event(crate::event::Event::PipelineExit(env)).await?;
+ write_event(Event::Exit(env)).await?;
if let Some(signal) = status.signal() {
nix::sys::signal::raise(signal.try_into().unwrap())?;
}
@@ -41,7 +47,7 @@ async fn read_data() -> anyhow::Result<crate::env::Env> {
Ok(env)
}
-async fn write_event(event: crate::event::Event) -> anyhow::Result<()> {
+async fn write_event(event: Event) -> anyhow::Result<()> {
let mut fd4 = unsafe { async_std::fs::File::from_raw_fd(4) };
fd4.write_all(&bincode::serialize(&event)?).await?;
fd4.flush().await?;
@@ -169,10 +175,8 @@ async fn wait_children(
}
nix::sys::wait::WaitStatus::Stopped(pid, signal) => {
if signal == nix::sys::signal::Signal::SIGTSTP {
- if let Err(e) = write_event(
- crate::event::Event::ChildSuspend(env.idx()),
- )
- .await
+ if let Err(e) =
+ write_event(Event::Suspend(env.idx())).await
{
bail!(e);
}
diff --git a/src/state/history/mod.rs b/src/state/history/mod.rs
index 8e69a5c..673b39c 100644
--- a/src/state/history/mod.rs
+++ b/src/state/history/mod.rs
@@ -626,7 +626,7 @@ async fn run_pipeline(
loop {
enum Res {
- Read(bincode::Result<crate::event::Event>),
+ Read(bincode::Result<crate::pipeline::Event>),
Exit(std::io::Result<std::process::ExitStatus>),
}
@@ -643,10 +643,13 @@ async fn run_pipeline(
};
let exit = async { Res::Exit(child.status_no_drop().await) };
match read.or(exit).await {
- Res::Read(Ok(crate::event::Event::PipelineExit(new_env))) => {
- *env = new_env;
- }
- Res::Read(Ok(event)) => event_w.send(event).await.unwrap(),
+ Res::Read(Ok(event)) => match event {
+ crate::pipeline::Event::Suspend(idx) => event_w
+ .send(crate::event::Event::ChildSuspend(idx))
+ .await
+ .unwrap(),
+ crate::pipeline::Event::Exit(new_env) => *env = new_env,
+ },
Res::Read(Err(e)) => {
if let bincode::ErrorKind::Io(e) = &*e {
if e.kind() == std::io::ErrorKind::UnexpectedEof {
diff --git a/src/state/mod.rs b/src/state/mod.rs
index 6873ba3..c09e687 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -189,10 +189,6 @@ impl State {
self.set_focus(Focus::Readline, None).await;
}
}
- crate::event::Event::PipelineExit(_) => {
- // this should be handled by the pipeline runner directly
- unreachable!();
- }
crate::event::Event::ClockTimer => {}
};
Some(Action::Refresh)