manen

Fancy Lua REPL
Log | Files | Refs | README | LICENSE

commit 540845230bff53d867b8dce329c67b95c36af83f
parent 67b49e180447c7f5c51019939dce271debb91612
Author: Sylvia Ivory <git@sivory.net>
Date:   Mon, 23 Jun 2025 17:12:05 -0700

Save command history

Diffstat:
MCargo.lock | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MCargo.toml | 1+
Msrc/editor.rs | 15++++++++++++---
3 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -304,6 +304,27 @@ dependencies = [ ] [[package]] +name = "directories" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.60.2", +] + +[[package]] name = "either" version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -378,6 +399,17 @@ dependencies = [ ] [[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] name = "gimli" version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -489,6 +521,16 @@ dependencies = [ ] [[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] name = "linux-raw-sys" version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -553,6 +595,7 @@ dependencies = [ "color-eyre", "comfy-table", "ctrlc", + "directories", "lazy_static", "mlua", "nu-ansi-term", @@ -672,6 +715,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" [[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] name = "owo-colors" version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -746,6 +795,17 @@ dependencies = [ ] [[package]] +name = "redox_users" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] name = "reedline" version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -22,6 +22,7 @@ clap = { version = "4.5.40", features = ["derive"] } color-eyre = "0.6.5" comfy-table = "7.1.4" ctrlc = "3.4.7" +directories = "6.0.0" lazy_static = "1.5.0" mlua = { version = "0.10.5", features = ["anyhow", "send", "async"] } nu-ansi-term = "0.50.1" diff --git a/src/editor.rs b/src/editor.rs @@ -6,10 +6,11 @@ use std::{ }, }; +use directories::ProjectDirs; use mlua::prelude::*; use reedline::{ - DefaultPrompt, DefaultPromptSegment, EditCommand, Emacs, KeyCode, KeyModifiers, Reedline, - ReedlineEvent, Signal, default_emacs_keybindings, + DefaultPrompt, DefaultPromptSegment, EditCommand, Emacs, FileBackedHistory, KeyCode, + KeyModifiers, Reedline, ReedlineEvent, Signal, default_emacs_keybindings, }; use crate::{ @@ -56,12 +57,20 @@ impl Editor { ReedlineEvent::Edit(vec![EditCommand::InsertNewline]), ); - let editor = Reedline::create() + let mut editor = Reedline::create() .with_highlighter(Box::new(LuaHighlighter::new())) .with_validator(Box::new(LuaValidator::new())) .with_hinter(Box::new(LuaHinter)) .with_edit_mode(Box::new(Emacs::new(keybindings))); + if let Some(proj_dirs) = ProjectDirs::from("net.sivory", "", "Manen") { + let history = FileBackedHistory::with_file(256, proj_dirs.data_dir().join("history")); + + if let Ok(history) = history { + editor = editor.with_history(Box::new(history)) + } + } + Ok(Self { prompt, editor,