From df5eec13a031d41232e7407794e2f5b9a0a2d608 Mon Sep 17 00:00:00 2001 From: Jonas Maier <> Date: Sat, 7 Mar 2026 20:49:52 +0100 Subject: history with relative time --- src/main.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 5e29a6e..9a4e692 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ pub mod parse; pub mod raw; pub mod reload; pub mod run; +pub mod date; use linebuf::LineBuf; use raw::*; @@ -57,10 +58,25 @@ type BString = Vec; #[allow(non_camel_case_types)] type bstr = [u8]; +#[derive(Clone)] +struct HistoryEntry { + pub time: date::DateTime, + pub cmd: BString, +} + +impl HistoryEntry { + pub fn new(cmd: BString) -> Self { + Self { + time: date::DateTime::now(), + cmd, + } + } +} + pub struct Session { raw: ScopedRawMode, line: LineBuf, - history: Vec, + history: Vec, prev_path: BString, builtins: HashMap, vars: HashMap, @@ -131,7 +147,7 @@ impl Session { let new = if self.history_visit == 0 { Vec::new() } else { - self.history[self.history.len() - self.history_visit].clone() + self.history[self.history.len() - self.history_visit].cmd.clone() }; io::stdout().write_all(&new).unwrap(); io::stdout().flush().unwrap(); @@ -311,7 +327,7 @@ fn event_loop() { let line = se.line.dump(); if !line.is_empty() { print!("\r\n"); - se.history.push(line.clone()); + se.history.push(HistoryEntry::new(line.clone())); se.history_visit = 0; drop(se); run::run(session.clone(), line); @@ -322,7 +338,7 @@ fn event_loop() { 127 => { if se.line.is_empty() && !se.line.is_dirty() && !se.history.is_empty() { // take previous command for editing - let cmd = se.history[se.history.len() - 1].clone(); + let cmd = se.history[se.history.len() - 1].cmd.clone(); se.type_bytes(&cmd); } else { se.del_left(); @@ -455,7 +471,7 @@ fn event_loop() { } b'|' if se.line.is_empty() && !se.history.is_empty() => { - let mut cmd = se.history[se.history.len() - 1].clone(); + let mut cmd = se.history[se.history.len() - 1].cmd.clone(); cmd.extend_from_slice(b" | "); io::stdout().write_all(&cmd).unwrap(); io::stdout().flush().unwrap(); -- cgit v1.2.3