From b5e1460151451e124f5e80e0dbe670fff83899c0 Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 24 Oct 2023 17:45:49 +0800 Subject: feat: use backslash at end of line for multiline text (#147) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: use backslash at end of line for multiline text ``` 〉.set dry_run true 〉abc \ def \ ijk >>> The following message consumes 12 tokens. abc def ijk ``` Deprecate old {}/() multi-line editing --- src/repl/mod.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'src/repl/mod.rs') diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 84f8175..2e68528 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -16,7 +16,6 @@ use crate::term; use anyhow::{Context, Result}; use reedline::Signal; -use std::borrow::Cow; use std::rc::Rc; pub const REPL_COMMANDS: [(&str, &str); 13] = [ @@ -86,7 +85,7 @@ impl Repl { } fn handle_line(&mut self, handler: &Rc, line: &str) -> Result { - let line = clean_multiline_symbols(line); + let line = line.trim().replace("\\\n", "\n"); match parse_command(line.as_ref()) { Some((cmd, args)) => match cmd { ".exit" => { @@ -165,21 +164,12 @@ fn dump_repl_help() { print_now!( r###"{head} -Type `{{` to enter the multi-line editing mode, type '}}' to exit the mode. Press Ctrl+C to abort readline, Ctrl+D to exit the REPL "###, ); } -fn clean_multiline_symbols(line: &str) -> Cow { - let trimed_line = line.trim(); - match trimed_line.chars().next() { - Some('{' | '[' | '(') => trimed_line[1..trimed_line.len() - 1].into(), - _ => Cow::Borrowed(line), - } -} - fn parse_command(line: &str) -> Option<(&str, Option<&str>)> { let mut trimed_line = line.trim_start(); if trimed_line.starts_with('.') { -- cgit v1.2.3