From 5e7db6e1051bf2c75d78258b33704c57d4236a53 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 8 Feb 2022 22:16:12 +0800 Subject: [PATCH] Use new version of rustyline. --- CHANGELOG.md | 7 ++++--- Cargo.toml | 4 +++- src/bin/rhai-repl.rs | 21 ++++++--------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba6d5d2d..4942004e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,15 +55,16 @@ The REPL bin tool, `rhai-rpl`, has been enhanced. ### Line editor -* `rhai-repl` now uses [`rustyline`](https://crates.io/crates/rustyline) as a line editor with history. -* Shift-Enter can now be used to enter multiple lines without having to attach the `\` continuation character the end of each line. +* `rhai-repl` now uses a modified version of [`rustyline`](https://crates.io/crates/rustyline) as a line editor with history. +* Ctrl-Enter can now be used to enter multiple lines without having to attach the `\` continuation character the end of each line. +* Bracketed paste is supported, even on Windows (version 10 or above), so pasting code directly into `rhai-repl` is made much more convenient. ### New commands * `strict` to turn on/off _Strict Variables Mode_. * `optimize` to turn on/off script optimization. * `history` to print lines history. -* `!!`, `!`_num_ and `!`_text_ to recall a history line. +* `!!`, `!`_num_, `!`_text_ and `!?`_text_ to recall a history line. * `keys` to print all key bindings. diff --git a/Cargo.toml b/Cargo.toml index 19fcad41..4fb2e519 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,9 @@ serde = { version = "1.0", default-features = false, features = ["derive", "allo serde_json = { version = "1.0", default-features = false, features = ["alloc"], optional = true } unicode-xid = { version = "0.2", default-features = false, optional = true } rust_decimal = { version = "1.16", default-features = false, features = ["maths"], optional = true } -rustyline = { version = "9", optional = true } +# notice that a custom modified version of `rustyline` is used which supports bracketed paste on Windows +# this can be moved to the official version when bracketed paste is added +rustyline = { version = "9", optional = true, git = "https://github.com/schungx/rustyline", branch = "bracketed_paste" } [dev-dependencies] serde_bytes = "0.11" diff --git a/src/bin/rhai-repl.rs b/src/bin/rhai-repl.rs index 8328dbe8..5d574860 100644 --- a/src/bin/rhai-repl.rs +++ b/src/bin/rhai-repl.rs @@ -62,8 +62,8 @@ fn print_help() { println!("ast => print the last AST (optimized)"); println!("astu => print the last raw, un-optimized AST"); println!(); - println!("press Shift-Enter to continue to the next line,"); - println!(r"or end a line with '\' (e.g. when pasting code)."); + println!("press Ctrl-Enter or end a line with `\\`"); + println!("to continue to the next line."); println!(); } @@ -204,6 +204,7 @@ fn load_script_files(engine: &mut Engine) { // Setup the Rustyline editor. fn setup_editor() -> Editor<()> { + //env_logger::init(); let config = Builder::new() .tab_stop(4) .indent_size(4) @@ -225,23 +226,13 @@ fn setup_editor() -> Editor<()> { Event::KeySeq(smallvec![KeyEvent::ctrl('z')]), EventHandler::Simple(Cmd::Undo(1)), ); - // Map Shift-Return to insert a new line - bypass need for `\` continuation + // Map Ctrl-Enter to insert a new line - bypass need for `\` continuation rl.bind_sequence( - Event::KeySeq(smallvec![KeyEvent( - KeyCode::Char('m'), - Modifiers::CTRL_SHIFT - )]), + Event::KeySeq(smallvec![KeyEvent(KeyCode::Char('J'), Modifiers::CTRL)]), EventHandler::Simple(Cmd::Newline), ); rl.bind_sequence( - Event::KeySeq(smallvec![KeyEvent( - KeyCode::Char('j'), - Modifiers::CTRL_SHIFT - )]), - EventHandler::Simple(Cmd::Newline), - ); - rl.bind_sequence( - Event::KeySeq(smallvec![KeyEvent(KeyCode::Enter, Modifiers::SHIFT)]), + Event::KeySeq(smallvec![KeyEvent(KeyCode::Enter, Modifiers::CTRL)]), EventHandler::Simple(Cmd::Newline), ); // Map Ctrl-Home and Ctrl-End for beginning/end of input