aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs26
1 files changed, 21 insertions, 5 deletions
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<u8>;
#[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<BString>,
+ history: Vec<HistoryEntry>,
prev_path: BString,
builtins: HashMap<BString, &'static dyn run::Builtin>,
vars: HashMap<BString, BString>,
@@ -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();