manen

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

commit 24d6d1320d7e9445b4017346fbe1200ac5292c65
parent c769ad6f7a67d6d9ee72af4b9109a9c0cafbd49f
Author: Sylvia Ivory <git@sivory.net>
Date:   Sat, 21 Jun 2025 16:03:57 -0700

Add Shift+Enter keybind

Diffstat:
M.gitignore | 1+
Msrc/editor.rs | 15+++++++++++++--
Msrc/validator.rs | 2+-
3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1 +1,2 @@ /target +/notes.md diff --git a/src/editor.rs b/src/editor.rs @@ -1,5 +1,8 @@ use mlua::prelude::*; -use reedline::{DefaultPrompt, DefaultPromptSegment, Reedline, Signal}; +use reedline::{ + DefaultPrompt, DefaultPromptSegment, EditCommand, Emacs, KeyCode, KeyModifiers, Reedline, + ReedlineEvent, Signal, default_emacs_keybindings, +}; use crate::{ format::{TableFormat, lua_to_string}, @@ -25,10 +28,18 @@ impl Editor { DefaultPromptSegment::Empty, ); + let mut keybindings = default_emacs_keybindings(); + keybindings.add_binding( + KeyModifiers::SHIFT, + KeyCode::Enter, + ReedlineEvent::Edit(vec![EditCommand::InsertNewline]), + ); + let editor = Reedline::create() .with_highlighter(Box::new(LuaHighlighter::new())) .with_validator(Box::new(LuaValidator::new())) - .with_hinter(Box::new(LuaValidator::new())); + .with_hinter(Box::new(LuaValidator::new())) + .with_edit_mode(Box::new(Emacs::new(keybindings))); Ok(Self { prompt, diff --git a/src/validator.rs b/src/validator.rs @@ -33,7 +33,7 @@ impl LuaValidator { impl Validator for LuaValidator { fn validate(&self, line: &str) -> ValidationResult { if line.starts_with(".") { - return ValidationResult::Complete + return ValidationResult::Complete; } match self.lua.load(line).into_function() {