summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock50
-rw-r--r--Cargo.toml1
-rw-r--r--src/history.rs28
-rw-r--r--src/util.rs18
4 files changed, 95 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1edc916..7b8e735 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -200,6 +200,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
+name = "chrono"
+version = "0.4.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
+dependencies = [
+ "libc",
+ "num-integer",
+ "num-traits",
+ "time",
+ "winapi",
+]
+
+[[package]]
name = "concurrent-queue"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -377,6 +390,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"async-std",
+ "chrono",
"futures-lite",
"libc",
"nix",
@@ -403,6 +417,25 @@ dependencies = [
]
[[package]]
+name = "num-integer"
+version = "0.1.44"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
+dependencies = [
+ "autocfg",
+ "num-traits",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -580,6 +613,17 @@ dependencies = [
]
[[package]]
+name = "time"
+version = "0.1.44"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
+dependencies = [
+ "libc",
+ "wasi",
+ "winapi",
+]
+
+[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -651,6 +695,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
[[package]]
+name = "wasi"
+version = "0.10.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
+
+[[package]]
name = "wasm-bindgen"
version = "0.2.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index e5cb362..649f174 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,6 +8,7 @@ license = "MIT"
[dependencies]
anyhow = "1.0.45"
async-std = { version = "1.10.0", features = ["unstable"] }
+chrono = "0.4.19"
futures-lite = "1.12.0"
libc = "0.2.107"
nix = "0.23.0"
diff --git a/src/history.rs b/src/history.rs
index 09299ad..3615ec9 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -69,8 +69,10 @@ impl History {
// 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);
+ let mut entry = task_entry.lock_arc().await;
+ entry.exit_status = Some(status);
+ entry.end_instant =
+ Some(std::time::Instant::now());
task_action
.send(crate::action::Action::UpdateFocus(
crate::state::Focus::Readline,
@@ -237,6 +239,22 @@ impl History {
}
out.write_str(&entry.cmd);
out.reset_attributes();
+ let time = if let Some(end_instant) = entry.end_instant {
+ format!(
+ "[{} ({})]",
+ entry.start_time.time().format("%H:%M:%S"),
+ crate::util::format_duration(
+ end_instant - entry.start_instant
+ )
+ )
+ } else {
+ format!("[{}]", entry.start_time.time().format("%H:%M:%S"))
+ };
+ out.move_to(
+ (self.size.0 as usize - used_lines).try_into().unwrap(),
+ (self.size.1 as usize - time.len() - 1).try_into().unwrap(),
+ );
+ out.write_str(&time);
if last_row > 5 {
out.write(b"\r\n");
out.set_bgcolor(textmode::color::RED);
@@ -298,6 +316,9 @@ struct HistoryEntry {
input: async_std::channel::Sender<Vec<u8>>,
resize: async_std::channel::Sender<(u16, u16)>,
exit_status: Option<async_std::process::ExitStatus>,
+ start_time: chrono::DateTime<chrono::Local>,
+ start_instant: std::time::Instant,
+ end_instant: Option<std::time::Instant>,
}
impl HistoryEntry {
@@ -315,6 +336,9 @@ impl HistoryEntry {
input,
resize,
exit_status: None,
+ start_time: chrono::Local::now(),
+ start_instant: std::time::Instant::now(),
+ end_instant: None,
}
}
diff --git a/src/util.rs b/src/util.rs
index d792b91..649888c 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -3,3 +3,21 @@ pub type Mutex<T> = async_std::sync::Arc<async_std::sync::Mutex<T>>;
pub fn mutex<T>(t: T) -> Mutex<T> {
async_std::sync::Arc::new(async_std::sync::Mutex::new(t))
}
+
+pub fn format_duration(dur: std::time::Duration) -> String {
+ let secs = dur.as_secs();
+ let nanos = dur.subsec_nanos();
+ if secs > 60 {
+ let mins = secs / 60;
+ let secs = secs - mins * 60;
+ format!("{}m{}s", mins, secs)
+ } else if secs > 0 {
+ format!("{}.{:03}s", secs, nanos / 1_000_000)
+ } else if nanos >= 1_000_000 {
+ format!("{}ms", nanos / 1_000_000)
+ } else if nanos >= 1_000 {
+ format!("{}us", nanos / 1_000)
+ } else {
+ format!("{}ns", nanos)
+ }
+}