summaryrefslogtreecommitdiffstats
path: root/src/history.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-11-13 03:24:52 -0500
committerJesse Luehrs <doy@tozt.net>2021-11-13 03:24:52 -0500
commit7c0da0cd97536a9c412d91524971f00af87d1bdc (patch)
tree9a7eedd29eead664a824cc2c6ffe07e84b66ab27 /src/history.rs
parentf28ba66113d0ab2ceecd169e1fb07401074dc056 (diff)
downloadnbsh-7c0da0cd97536a9c412d91524971f00af87d1bdc.tar.gz
nbsh-7c0da0cd97536a9c412d91524971f00af87d1bdc.zip
track exit status of processes
Diffstat (limited to 'src/history.rs')
-rw-r--r--src/history.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/history.rs b/src/history.rs
index 73ace52..09299ad 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -1,6 +1,7 @@
use async_std::io::{ReadExt as _, WriteExt as _};
use futures_lite::future::FutureExt as _;
use pty_process::Command as _;
+use std::os::unix::process::ExitStatusExt as _;
use textmode::Textmode as _;
pub struct History {
@@ -26,7 +27,7 @@ impl History {
let (exe, args) = parse_cmd(cmd);
let mut process = async_std::process::Command::new(&exe);
process.args(&args);
- let child = process
+ let mut child = process
.spawn_pty(Some(&pty_process::Size::new(
self.size.0,
self.size.1,
@@ -65,7 +66,11 @@ impl History {
if e.raw_os_error() != Some(libc::EIO) {
eprintln!("pty read failed: {:?}", e);
}
- task_entry.lock_arc().await.running = false;
+ // XXX not sure if this is safe - are we sure
+ // the child exited?
+ let status = child.status().await.unwrap();
+ task_entry.lock_arc().await.exit_status =
+ Some(status);
task_action
.send(crate::action::Action::UpdateFocus(
crate::state::Focus::Readline,
@@ -219,8 +224,15 @@ impl History {
(self.size.0 as usize - used_lines).try_into().unwrap(),
0,
);
+ if let Some(status) = entry.exit_status {
+ if let Some(sig) = status.signal() {
+ out.write_str(&format!("SIG{} ", sig));
+ } else {
+ out.write_str(&format!("{} ", status.code().unwrap()));
+ }
+ }
out.write_str("$ ");
- if entry.running {
+ if entry.running() {
out.set_bgcolor(textmode::Color::Rgb(16, 64, 16));
}
out.write_str(&entry.cmd);
@@ -256,7 +268,7 @@ impl History {
self.size = size;
for entry in &self.entries {
let entry = entry.lock_arc().await;
- if entry.running {
+ if entry.running() {
entry.resize.send(size).await.unwrap();
}
}
@@ -285,8 +297,7 @@ struct HistoryEntry {
visual_bell_state: usize,
input: async_std::channel::Sender<Vec<u8>>,
resize: async_std::channel::Sender<(u16, u16)>,
- running: bool, // option end time
- // start time
+ exit_status: Option<async_std::process::ExitStatus>,
}
impl HistoryEntry {
@@ -303,9 +314,13 @@ impl HistoryEntry {
visual_bell_state: 0,
input,
resize,
- running: true,
+ exit_status: None,
}
}
+
+ fn running(&self) -> bool {
+ self.exit_status.is_none()
+ }
}
fn parse_cmd(full_cmd: &str) -> (String, Vec<String>) {