From 9cd1a2acfef629be9c4bc79028cfd596a699f79d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Mon, 21 Oct 2024 17:50:42 +0200 Subject: [PATCH 1/4] the core idea --- src/tty/unix.rs | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/tty/unix.rs b/src/tty/unix.rs index 054b4f118..790f0ab08 100644 --- a/src/tty/unix.rs +++ b/src/tty/unix.rs @@ -7,6 +7,7 @@ use std::fs::{File, OpenOptions}; #[cfg(not(feature = "buffer-redux"))] use std::io::BufReader; use std::io::{self, ErrorKind, Read, Write}; +use std::ops::Deref; use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, IntoRawFd, RawFd}; use std::os::unix::net::UnixStream; use std::sync::atomic::{AtomicBool, Ordering}; @@ -987,6 +988,8 @@ impl Renderer for PosixRenderer { new_layout: &Layout, highlighter: Option<&dyn Highlighter>, ) -> Result<()> { + let continuation = "| "; + use std::fmt::Write; self.buffer.clear(); @@ -996,19 +999,34 @@ impl Renderer for PosixRenderer { self.clear_old_rows(old_layout); + // display the prompt if let Some(highlighter) = highlighter { - // display the prompt self.buffer .push_str(&highlighter.highlight_prompt(prompt, default_prompt)); - // display the input line - self.buffer - .push_str(&highlighter.highlight(line, line.pos())); } else { - // display the prompt self.buffer.push_str(prompt); - // display the input line - self.buffer.push_str(line); } + + // display the input line + let line = if let Some(highlighter) = highlighter { + highlighter.highlight(line, line.pos()) + } else { + std::borrow::Cow::from(line.deref()) + }; + if continuation.is_empty() { + self.buffer.push_str(&line); + } else { + let mut lines = line.split('\n'); + if let Some(first) = lines.next() { + self.buffer.push_str(first); + } + for line in lines { + self.buffer.push('\n'); + self.buffer.push_str(continuation); + self.buffer.push_str(line); + } + } + // display hint if let Some(hint) = hint { if let Some(highlighter) = highlighter { @@ -1023,6 +1041,9 @@ impl Renderer for PosixRenderer { && !hint.map_or_else(|| line.ends_with('\n'), |h| h.ends_with('\n')) { self.buffer.push('\n'); + if !continuation.is_empty() { + self.buffer.push_str(continuation); + } } // position the cursor let new_cursor_row_movement = end_pos.row - cursor.row; @@ -1049,12 +1070,14 @@ impl Renderer for PosixRenderer { /// Control characters are treated as having zero width. /// Characters with 2 column width are correctly handled (not split). fn calculate_position(&self, s: &str, orig: Position) -> Position { + let continuation = "| "; + let mut pos = orig; let mut esc_seq = 0; for c in s.graphemes(true) { if c == "\n" { pos.row += 1; - pos.col = 0; + pos.col = continuation.len(); continue; } let cw = if c == "\t" { @@ -1069,7 +1092,7 @@ impl Renderer for PosixRenderer { } } if pos.col == self.cols { - pos.col = 0; + pos.col = continuation.len(); pos.row += 1; } pos From 8327ebeb3c397b40108f05aa864eaeb7a72153fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Mon, 21 Oct 2024 17:55:03 +0200 Subject: [PATCH 2/4] add continuation to Writer and State --- src/edit.rs | 39 +++++++++++++++++++++++++++------------ src/lib.rs | 11 ++++++----- src/tty/mod.rs | 10 ++++++---- src/tty/test.rs | 3 ++- src/tty/unix.rs | 17 +++++++---------- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/edit.rs b/src/edit.rs index b18de9e2e..b0bede262 100644 --- a/src/edit.rs +++ b/src/edit.rs @@ -27,7 +27,8 @@ pub struct State<'out, 'prompt, H: Helper> { pub out: &'out mut ::Writer, prompt: &'prompt str, // Prompt to display (rl_prompt) prompt_size: Position, // Prompt Unicode/visible width and height - pub line: LineBuffer, // Edited line buffer + continuation: &'prompt str, + pub line: LineBuffer, // Edited line buffer pub layout: Layout, saved_line_for_history: LineBuffer, // Current edited line before history browsing byte_buffer: [u8; 4], @@ -48,14 +49,16 @@ impl<'out, 'prompt, H: Helper> State<'out, 'prompt, H> { pub fn new( out: &'out mut ::Writer, prompt: &'prompt str, + continuation: &'prompt str, helper: Option<&'out H>, ctx: Context<'out>, ) -> Self { - let prompt_size = out.calculate_position(prompt, Position::default()); + let prompt_size = out.calculate_position(prompt, Position::default(), continuation); Self { out, prompt, prompt_size, + continuation, line: LineBuffer::with_capacity(MAX_LINE).can_growth(true), layout: Layout::default(), saved_line_for_history: LineBuffer::with_capacity(MAX_LINE).can_growth(true), @@ -93,9 +96,11 @@ impl<'out, 'prompt, H: Helper> State<'out, 'prompt, H> { if new_cols != old_cols && (self.layout.end.row > 0 || self.layout.end.col >= new_cols) { - self.prompt_size = self - .out - .calculate_position(self.prompt, Position::default()); + self.prompt_size = self.out.calculate_position( + self.prompt, + Position::default(), + self.continuation, + ); self.refresh_line()?; } continue; @@ -122,9 +127,11 @@ impl<'out, 'prompt, H: Helper> State<'out, 'prompt, H> { pub fn move_cursor(&mut self, kind: CmdKind) -> Result<()> { // calculate the desired position of the cursor - let cursor = self - .out - .calculate_position(&self.line[..self.line.pos()], self.prompt_size); + let cursor = self.out.calculate_position( + &self.line[..self.line.pos()], + self.prompt_size, + self.continuation, + ); if self.layout.cursor == cursor { return Ok(()); } @@ -172,9 +179,13 @@ impl<'out, 'prompt, H: Helper> State<'out, 'prompt, H> { None }; - let new_layout = self - .out - .compute_layout(prompt_size, default_prompt, &self.line, info); + let new_layout = self.out.compute_layout( + prompt_size, + default_prompt, + &self.line, + info, + self.continuation, + ); debug!(target: "rustyline", "old layout: {:?}", self.layout); debug!(target: "rustyline", "new layout: {:?}", new_layout); @@ -185,6 +196,7 @@ impl<'out, 'prompt, H: Helper> State<'out, 'prompt, H> { &self.layout, &new_layout, highlighter, + self.continuation, )?; self.layout = new_layout; @@ -275,7 +287,9 @@ impl Refresher for State<'_, '_, H> { } fn refresh_prompt_and_line(&mut self, prompt: &str) -> Result<()> { - let prompt_size = self.out.calculate_position(prompt, Position::default()); + let prompt_size = + self.out + .calculate_position(prompt, Position::default(), self.continuation); self.hint(); self.highlight_char(CmdKind::Other); self.refresh(prompt, prompt_size, false, Info::Hint) @@ -753,6 +767,7 @@ pub fn init_state<'out, H: Helper>( out, prompt: "", prompt_size: Position::default(), + continuation: "", line: LineBuffer::init(line, pos), layout: Layout::default(), saved_line_for_history: LineBuffer::with_capacity(100), diff --git a/src/lib.rs b/src/lib.rs index 701565037..742461e8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -635,7 +635,7 @@ impl Editor { /// Otherwise (e.g., if `stdin` is a pipe or the terminal is not supported), /// it uses file-style interaction. pub fn readline(&mut self, prompt: &str) -> Result { - self.readline_with(prompt, None) + self.readline_with(prompt, "", None) } /// This function behaves in the exact same manner as `readline`, except @@ -646,10 +646,10 @@ impl Editor { /// the cursor and the string on the right is what will appear to the /// right of the cursor. pub fn readline_with_initial(&mut self, prompt: &str, initial: (&str, &str)) -> Result { - self.readline_with(prompt, Some(initial)) + self.readline_with(prompt, "", Some(initial)) } - fn readline_with(&mut self, prompt: &str, initial: Option<(&str, &str)>) -> Result { + fn readline_with(&mut self, prompt: &str, continuation: &str, initial: Option<(&str, &str)>) -> Result { if self.term.is_unsupported() { debug!(target: "rustyline", "unsupported terminal"); // Write prompt and flush it to stdout @@ -661,7 +661,7 @@ impl Editor { } else if self.term.is_input_tty() { let (original_mode, term_key_map) = self.term.enable_raw_mode()?; let guard = Guard(&original_mode); - let user_input = self.readline_edit(prompt, initial, &original_mode, term_key_map); + let user_input = self.readline_edit(prompt, continuation, initial, &original_mode, term_key_map); if self.config.auto_add_history() { if let Ok(ref line) = user_input { self.add_history_entry(line.as_str())?; @@ -683,6 +683,7 @@ impl Editor { fn readline_edit( &mut self, prompt: &str, + continuation: &str, initial: Option<(&str, &str)>, original_mode: &tty::Mode, term_key_map: tty::KeyMap, @@ -691,7 +692,7 @@ impl Editor { self.kill_ring.reset(); // TODO recreate a new kill ring vs reset let ctx = Context::new(&self.history); - let mut s = State::new(&mut stdout, prompt, self.helper.as_ref(), ctx); + let mut s = State::new(&mut stdout, prompt, continuation, self.helper.as_ref(), ctx); let mut input_state = InputState::new(&self.config, &self.custom_bindings); diff --git a/src/tty/mod.rs b/src/tty/mod.rs index 22dcb8a2b..f5b9952db 100644 --- a/src/tty/mod.rs +++ b/src/tty/mod.rs @@ -54,6 +54,7 @@ pub trait Renderer { old_layout: &Layout, new_layout: &Layout, highlighter: Option<&dyn Highlighter>, + continuation: &str, ) -> Result<()>; /// Compute layout for rendering prompt + line + some info (either hint, @@ -65,18 +66,19 @@ pub trait Renderer { default_prompt: bool, line: &LineBuffer, info: Option<&str>, + continuation: &str, ) -> Layout { // calculate the desired position of the cursor let pos = line.pos(); - let cursor = self.calculate_position(&line[..pos], prompt_size); + let cursor = self.calculate_position(&line[..pos], prompt_size, continuation); // calculate the position of the end of the input line let mut end = if pos == line.len() { cursor } else { - self.calculate_position(&line[pos..], cursor) + self.calculate_position(&line[pos..], cursor, continuation) }; if let Some(info) = info { - end = self.calculate_position(info, end); + end = self.calculate_position(info, end, continuation); } let new_layout = Layout { @@ -92,7 +94,7 @@ pub trait Renderer { /// Calculate the number of columns and rows used to display `s` on a /// `cols` width terminal starting at `orig`. - fn calculate_position(&self, s: &str, orig: Position) -> Position; + fn calculate_position(&self, s: &str, orig: Position, continuation: &str) -> Position; fn write_and_flush(&mut self, buf: &str) -> Result<()>; diff --git a/src/tty/test.rs b/src/tty/test.rs index 3478baf9f..314e4bbcc 100644 --- a/src/tty/test.rs +++ b/src/tty/test.rs @@ -108,11 +108,12 @@ impl Renderer for Sink { _old_layout: &Layout, _new_layout: &Layout, _highlighter: Option<&dyn Highlighter>, + _continuation: &str, ) -> Result<()> { Ok(()) } - fn calculate_position(&self, s: &str, orig: Position) -> Position { + fn calculate_position(&self, s: &str, orig: Position, _c: &str) -> Position { let mut pos = orig; pos.col += s.len(); pos diff --git a/src/tty/unix.rs b/src/tty/unix.rs index 790f0ab08..030095481 100644 --- a/src/tty/unix.rs +++ b/src/tty/unix.rs @@ -987,9 +987,8 @@ impl Renderer for PosixRenderer { old_layout: &Layout, new_layout: &Layout, highlighter: Option<&dyn Highlighter>, + continuation: &str, ) -> Result<()> { - let continuation = "| "; - use std::fmt::Write; self.buffer.clear(); @@ -1069,9 +1068,7 @@ impl Renderer for PosixRenderer { /// Control characters are treated as having zero width. /// Characters with 2 column width are correctly handled (not split). - fn calculate_position(&self, s: &str, orig: Position) -> Position { - let continuation = "| "; - + fn calculate_position(&self, s: &str, orig: Position, continuation: &str) -> Position { let mut pos = orig; let mut esc_seq = 0; for c in s.graphemes(true) { @@ -1671,7 +1668,7 @@ mod test { #[ignore] fn prompt_with_ansi_escape_codes() { let out = PosixRenderer::new(libc::STDOUT_FILENO, 4, true, BellStyle::default()); - let pos = out.calculate_position("\x1b[1;32m>>\x1b[0m ", Position::default()); + let pos = out.calculate_position("\x1b[1;32m>>\x1b[0m ", Position::default(), ""); assert_eq!(3, pos.col); assert_eq!(0, pos.row); } @@ -1702,10 +1699,10 @@ mod test { let mut out = PosixRenderer::new(libc::STDOUT_FILENO, 4, true, BellStyle::default()); let prompt = "> "; let default_prompt = true; - let prompt_size = out.calculate_position(prompt, Position::default()); + let prompt_size = out.calculate_position(prompt, Position::default(), ""); let mut line = LineBuffer::init("", 0); - let old_layout = out.compute_layout(prompt_size, default_prompt, &line, None); + let old_layout = out.compute_layout(prompt_size, default_prompt, &line, None, ""); assert_eq!(Position { col: 2, row: 0 }, old_layout.cursor); assert_eq!(old_layout.cursor, old_layout.end); @@ -1713,10 +1710,10 @@ mod test { Some(true), line.insert('a', out.cols - prompt_size.col + 1, &mut NoListener) ); - let new_layout = out.compute_layout(prompt_size, default_prompt, &line, None); + let new_layout = out.compute_layout(prompt_size, default_prompt, &line, None, ""); assert_eq!(Position { col: 1, row: 1 }, new_layout.cursor); assert_eq!(new_layout.cursor, new_layout.end); - out.refresh_line(prompt, &line, None, &old_layout, &new_layout, None) + out.refresh_line(prompt, &line, None, &old_layout, &new_layout, None, "") .unwrap(); #[rustfmt::skip] assert_eq!( From 47f59ca191c51768a8c38c6a453a64975eb5c13e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Mon, 21 Oct 2024 18:00:31 +0200 Subject: [PATCH 3/4] breaking: add `continuation` to `readline` and `readline_with_initial` --- src/lib.rs | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 742461e8c..c9d02ed04 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -634,8 +634,8 @@ impl Editor { /// terminal. /// Otherwise (e.g., if `stdin` is a pipe or the terminal is not supported), /// it uses file-style interaction. - pub fn readline(&mut self, prompt: &str) -> Result { - self.readline_with(prompt, "", None) + pub fn readline(&mut self, prompt: &str, continuation: &str) -> Result { + self.readline_with(prompt, continuation, None) } /// This function behaves in the exact same manner as `readline`, except @@ -645,11 +645,21 @@ impl Editor { /// The string on the left of the tuple is what will appear to the left of /// the cursor and the string on the right is what will appear to the /// right of the cursor. - pub fn readline_with_initial(&mut self, prompt: &str, initial: (&str, &str)) -> Result { - self.readline_with(prompt, "", Some(initial)) + pub fn readline_with_initial( + &mut self, + prompt: &str, + continuation: &str, + initial: (&str, &str), + ) -> Result { + self.readline_with(prompt, continuation, Some(initial)) } - fn readline_with(&mut self, prompt: &str, continuation: &str, initial: Option<(&str, &str)>) -> Result { + fn readline_with( + &mut self, + prompt: &str, + continuation: &str, + initial: Option<(&str, &str)>, + ) -> Result { if self.term.is_unsupported() { debug!(target: "rustyline", "unsupported terminal"); // Write prompt and flush it to stdout @@ -661,7 +671,8 @@ impl Editor { } else if self.term.is_input_tty() { let (original_mode, term_key_map) = self.term.enable_raw_mode()?; let guard = Guard(&original_mode); - let user_input = self.readline_edit(prompt, continuation, initial, &original_mode, term_key_map); + let user_input = + self.readline_edit(prompt, continuation, initial, &original_mode, term_key_map); if self.config.auto_add_history() { if let Ok(ref line) = user_input { self.add_history_entry(line.as_str())?; @@ -886,10 +897,15 @@ impl Editor { /// } /// # Ok::<(), rustyline::error::ReadlineError>(()) /// ``` - pub fn iter<'a>(&'a mut self, prompt: &'a str) -> impl Iterator> + 'a { + pub fn iter<'a>( + &'a mut self, + prompt: &'a str, + continuation: &'a str, + ) -> impl Iterator> + 'a { Iter { editor: self, prompt, + continuation, } } @@ -966,13 +982,14 @@ impl fmt::Debug for Editor { struct Iter<'a, H: Helper, I: History> { editor: &'a mut Editor, prompt: &'a str, + continuation: &'a str, } impl Iterator for Iter<'_, H, I> { type Item = Result; fn next(&mut self) -> Option> { - let readline = self.editor.readline(self.prompt); + let readline = self.editor.readline(self.prompt, self.continuation); match readline { Ok(l) => Some(Ok(l)), Err(ReadlineError::Eof) => None, From 520543765bd34aba07d0c35e7adec9aa8face0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Mon, 21 Oct 2024 18:01:23 +0200 Subject: [PATCH 4/4] deal with breakage --- README.md | 2 +- examples/custom_key_bindings.rs | 2 +- examples/diy_hints.rs | 2 +- examples/example.rs | 2 +- examples/external_print.rs | 2 +- examples/input_multiline.rs | 2 +- examples/input_validation.rs | 2 +- examples/minimal.rs | 2 +- examples/numeric_input.rs | 2 +- examples/read_password.rs | 4 ++-- examples/sqlite_history.rs | 2 +- src/lib.rs | 4 ++-- src/test/common.rs | 8 ++++---- src/test/mod.rs | 8 ++++---- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index d6bf9c684..45b906051 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ fn main() -> Result<()> { println!("No previous history."); } loop { - let readline = rl.readline(">> "); + let readline = rl.readline(">> ", ""); match readline { Ok(line) => { rl.add_history_entry(line.as_str()); diff --git a/examples/custom_key_bindings.rs b/examples/custom_key_bindings.rs index 7d6624af7..1cc51dbef 100644 --- a/examples/custom_key_bindings.rs +++ b/examples/custom_key_bindings.rs @@ -101,7 +101,7 @@ fn main() -> Result<()> { ); loop { - let line = rl.readline("> ")?; + let line = rl.readline("> ", "")?; rl.add_history_entry(line.as_str())?; println!("Line: {line}"); } diff --git a/examples/diy_hints.rs b/examples/diy_hints.rs index af8fadc80..95a3a350c 100644 --- a/examples/diy_hints.rs +++ b/examples/diy_hints.rs @@ -90,7 +90,7 @@ fn main() -> Result<()> { rl.set_helper(Some(h)); loop { - let input = rl.readline("> ")?; + let input = rl.readline("> ", "")?; println!("input: {input}"); } } diff --git a/examples/example.rs b/examples/example.rs index d258064c6..65794c606 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -73,7 +73,7 @@ fn main() -> rustyline::Result<()> { loop { let p = format!("{count}> "); rl.helper_mut().expect("No helper").colored_prompt = format!("\x1b[1;32m{p}\x1b[0m"); - let readline = rl.readline(&p); + let readline = rl.readline(&p, ""); match readline { Ok(line) => { rl.add_history_entry(line.as_str())?; diff --git a/examples/external_print.rs b/examples/external_print.rs index f93769e95..db931310b 100644 --- a/examples/external_print.rs +++ b/examples/external_print.rs @@ -22,7 +22,7 @@ fn main() -> Result<()> { }); loop { - let line = rl.readline("> ")?; + let line = rl.readline("> ", "")?; rl.add_history_entry(line.as_str())?; println!("Line: {line}"); } diff --git a/examples/input_multiline.rs b/examples/input_multiline.rs index ead5e8825..dbc907966 100644 --- a/examples/input_multiline.rs +++ b/examples/input_multiline.rs @@ -23,7 +23,7 @@ fn main() -> Result<()> { EventHandler::Simple(Cmd::Newline), ); - let input = rl.readline("> ")?; + let input = rl.readline("ml> ", "... ")?; println!("Input: {input}"); Ok(()) diff --git a/examples/input_validation.rs b/examples/input_validation.rs index 583d94f62..711f6847c 100644 --- a/examples/input_validation.rs +++ b/examples/input_validation.rs @@ -25,7 +25,7 @@ fn main() -> Result<()> { let mut rl = Editor::new()?; rl.set_helper(Some(h)); - let input = rl.readline("> ")?; + let input = rl.readline("> ", "")?; println!("Input: {input}"); Ok(()) } diff --git a/examples/minimal.rs b/examples/minimal.rs index 9fc627ee4..fb8be505b 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -5,7 +5,7 @@ fn main() -> Result<()> { env_logger::init(); let mut rl = DefaultEditor::new()?; loop { - let line = rl.readline("> ")?; // read + let line = rl.readline("> ", "")?; // read println!("Line: {line}"); // eval / print } // loop } diff --git a/examples/numeric_input.rs b/examples/numeric_input.rs index 49eb6f94b..07ccd0a1c 100644 --- a/examples/numeric_input.rs +++ b/examples/numeric_input.rs @@ -27,7 +27,7 @@ fn main() -> Result<()> { ); loop { - let line = rl.readline("> ")?; + let line = rl.readline("> ", "")?; println!("Num: {line}"); } } diff --git a/examples/read_password.rs b/examples/read_password.rs index d93418ae2..89d898c49 100644 --- a/examples/read_password.rs +++ b/examples/read_password.rs @@ -35,14 +35,14 @@ fn main() -> Result<()> { let mut rl = Editor::new()?; rl.set_helper(Some(h)); - let username = rl.readline("Username:")?; + let username = rl.readline("Username:", "")?; println!("Username: {username}"); rl.helper_mut().expect("No helper").masking = true; rl.set_color_mode(ColorMode::Forced); // force masking rl.set_auto_add_history(false); // make sure password is not added to history let mut guard = rl.set_cursor_visibility(false)?; - let passwd = rl.readline("Password:")?; + let passwd = rl.readline("Password:", "")?; guard.take(); println!("Secret: {passwd}"); Ok(()) diff --git a/examples/sqlite_history.rs b/examples/sqlite_history.rs index a1efac840..8a4209c78 100644 --- a/examples/sqlite_history.rs +++ b/examples/sqlite_history.rs @@ -11,7 +11,7 @@ fn main() -> Result<()> { }; let mut rl: Editor<(), _> = Editor::with_history(config, history)?; loop { - let line = rl.readline("> ")?; + let line = rl.readline("> ", "")?; println!("{line}"); } } diff --git a/src/lib.rs b/src/lib.rs index c9d02ed04..3e1489499 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ //! //! ``` //! let mut rl = rustyline::DefaultEditor::new()?; -//! let readline = rl.readline(">> "); +//! let readline = rl.readline(">> ", ""); //! match readline { //! Ok(line) => println!("Line: {:?}", line), //! Err(_) => println!("No input"), @@ -884,7 +884,7 @@ impl Editor { /// Iterator ends at [EOF](ReadlineError::Eof). /// ``` /// let mut rl = rustyline::DefaultEditor::new()?; - /// for readline in rl.iter("> ") { + /// for readline in rl.iter("> ", "") { /// match readline { /// Ok(line) => { /// println!("Line: {}", line); diff --git a/src/test/common.rs b/src/test/common.rs index d426b5f55..7e6f8a20f 100644 --- a/src/test/common.rs +++ b/src/test/common.rs @@ -157,7 +157,7 @@ fn newline_key() { fn eof_key() { for mode in &[EditMode::Emacs, EditMode::Vi] { let mut editor = init_editor(*mode, &[E::ctrl('D')]); - let err = editor.readline(">>"); + let err = editor.readline(">>", ""); assert_matches!(err, Err(ReadlineError::Eof)); } assert_line( @@ -176,16 +176,16 @@ fn eof_key() { fn interrupt_key() { for mode in &[EditMode::Emacs, EditMode::Vi] { let mut editor = init_editor(*mode, &[E::ctrl('C')]); - let err = editor.readline(">>"); + let err = editor.readline(">>", ""); assert_matches!(err, Err(ReadlineError::Interrupted)); let mut editor = init_editor(*mode, &[E::ctrl('C')]); - let err = editor.readline_with_initial(">>", ("Hi", "")); + let err = editor.readline_with_initial(">>", "", ("Hi", "")); assert_matches!(err, Err(ReadlineError::Interrupted)); if *mode == EditMode::Vi { // vi command mode let mut editor = init_editor(*mode, &[E::ESC, E::ctrl('C')]); - let err = editor.readline_with_initial(">>", ("Hi", "")); + let err = editor.readline_with_initial(">>", "", ("Hi", "")); assert_matches!(err, Err(ReadlineError::Interrupted)); } } diff --git a/src/test/mod.rs b/src/test/mod.rs index 14ff9052b..7a59c5cc3 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -104,7 +104,7 @@ fn complete_symbol() { // `expected_line`: line after enter key fn assert_line(mode: EditMode, keys: &[KeyEvent], expected_line: &str) { let mut editor = init_editor(mode, keys); - let actual_line = editor.readline(">>").unwrap(); + let actual_line = editor.readline(">>", "").unwrap(); assert_eq!(expected_line, actual_line); } @@ -118,7 +118,7 @@ fn assert_line_with_initial( expected_line: &str, ) { let mut editor = init_editor(mode, keys); - let actual_line = editor.readline_with_initial(">>", initial).unwrap(); + let actual_line = editor.readline_with_initial(">>", "", initial).unwrap(); assert_eq!(expected_line, actual_line); } @@ -127,7 +127,7 @@ fn assert_line_with_initial( // `expected`: line status before enter key: strings before and after cursor fn assert_cursor(mode: EditMode, initial: (&str, &str), keys: &[KeyEvent], expected: (&str, &str)) { let mut editor = init_editor(mode, keys); - let actual_line = editor.readline_with_initial("", initial).unwrap(); + let actual_line = editor.readline_with_initial("", "", initial).unwrap(); assert_eq!(expected.0.to_owned() + expected.1, actual_line); assert_eq!(expected.0.len(), editor.term.cursor); } @@ -146,7 +146,7 @@ fn assert_history( for entry in entries { editor.history.add(entry).unwrap(); } - let actual_line = editor.readline(prompt).unwrap(); + let actual_line = editor.readline(prompt, "").unwrap(); assert_eq!(expected.0.to_owned() + expected.1, actual_line); if prompt.is_empty() { assert_eq!(expected.0.len(), editor.term.cursor);