aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorJonas Maier <>2026-03-08 11:58:38 +0100
committerJonas Maier <>2026-03-08 11:58:38 +0100
commit36b934d543f8cfedb0a74c52de0620be7d5fb106 (patch)
tree2082d908f0cbc80b2c83070142c7da15a29e1907 /src/main.rs
parentf005472ded09dc910598f0ce03d6318722ed2c5a (diff)
downloadpish-36b934d543f8cfedb0a74c52de0620be7d5fb106.tar.gz
persistent history
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs29
1 files changed, 6 insertions, 23 deletions
diff --git a/src/main.rs b/src/main.rs
index 3687cd0..c2cf375 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -27,6 +27,7 @@ use linebuf::LineBuf;
use raw::*;
use crate::cursor::{Direction, move_cursor};
+use crate::history::HistoryEntry;
use crate::parse::{Ast, PreExpansion};
macro_rules! print {
@@ -59,28 +60,6 @@ type BString = Vec<u8>;
#[allow(non_camel_case_types)]
type bstr = [u8];
-#[derive(Clone)]
-struct HistoryEntry {
- /// time of execution
- pub time: date::DateTime,
-
- /// absolute path where the command was executed
- pub loc: BString,
-
- /// the command
- pub cmd: BString,
-}
-
-impl HistoryEntry {
- pub fn new(cmd: BString) -> Self {
- Self {
- time: date::DateTime::now(),
- loc: current_dir().unwrap().as_os_str().as_encoded_bytes().to_vec(),
- cmd,
- }
- }
-}
-
pub struct Session {
raw: ScopedRawMode,
line: LineBuf,
@@ -259,6 +238,8 @@ fn read1() -> u8 {
}
fn event_loop() {
+ history::setup();
+
let stdin = io::stdin();
let stdout = io::stdout();
@@ -335,7 +316,9 @@ fn event_loop() {
let line = se.line.dump();
if !line.is_empty() {
print!("\r\n");
- se.history.push(HistoryEntry::new(line.clone()));
+ let entry = HistoryEntry::new(line.clone());
+ history::persist(&entry);
+ se.history.push(entry);
se.history_visit = 0;
drop(se);
run::run(session.clone(), line);