diff --git a/src/edit.rs b/src/edit.rs index 0cce2b66ea13ccabb2af2e7128ad949038891544..7dae766973e4ac463b7894793fd9954963c06c01 100644 --- a/src/edit.rs +++ b/src/edit.rs @@ -22,7 +22,7 @@ pub struct State<'out, 'prompt> { prompt: &'prompt str, // Prompt to display (rl_prompt) prompt_size: Position, // Prompt Unicode/visible width and height pub line: LineBuffer, // Edited line buffer - cursor: Position, /* Cursor position (relative to the start of the prompt + pub cursor: Position, /* Cursor position (relative to the start of the prompt * for `row`) */ pub old_rows: usize, // Number of rows used so far (from start of prompt to end of input) history_index: usize, // The history index we are currently editing diff --git a/src/lib.rs b/src/lib.rs index 8f8a061c6fb6205cb7afd76434e65672d5a0f903..d2ce92b49324aa63a17ea857613320bfb848a286 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -488,6 +488,10 @@ fn readline_edit<H: Helper>( }, // TODO CTRL-_ // undo Cmd::AcceptLine => { + #[cfg(test)] + { + editor.term.cursor = s.cursor.col; + } // Accept the line regardless of where the cursor is. try!(s.edit_move_end()); if s.hinter.is_some() { diff --git a/src/test/common.rs b/src/test/common.rs index 8205bc2d857197b5f21be11c7c9a355b6e80168b..1dd52adb4055271112e6e1afe49aa1313d2b335b 100644 --- a/src/test/common.rs +++ b/src/test/common.rs @@ -11,7 +11,7 @@ fn home_key() { #[test] fn end_key() { assert_cursor(("", ""), &[KeyPress::End, KeyPress::Enter], 0); - //assert_cursor(("H", "i"), &[KeyPress::End, KeyPress::Enter], 2); FIXME + assert_cursor(("H", "i"), &[KeyPress::End, KeyPress::Enter], 2); } #[test] diff --git a/src/test/mod.rs b/src/test/mod.rs index b74186834f15bfd447fe2450e5e4212d6bc275ea..10c0752c9808439347234c69d010ce4b50ed6984 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -59,7 +59,7 @@ fn assert_line_with_initial(initial: (&str, &str), keys: &[KeyPress], expected_l fn assert_cursor(initial: (&str, &str), keys: &[KeyPress], expected_cursor: usize) { let mut editor = init_editor(keys); editor.readline_with_initial("", initial).unwrap(); - assert_eq!(expected_cursor, editor.term.cursor.get()); + assert_eq!(expected_cursor, editor.term.cursor); } #[test] diff --git a/src/tty/test.rs b/src/tty/test.rs index 3d7933f64e3e93d46289c874602b239916e3239f..29a1e797c26bc32db7e2f9e43314f02bb0001ce6 100644 --- a/src/tty/test.rs +++ b/src/tty/test.rs @@ -1,7 +1,5 @@ //! Tests specific definitions -use std::cell::Cell; use std::iter::IntoIterator; -use std::rc::Rc; use std::slice::Iter; use std::vec::IntoIter; @@ -50,24 +48,16 @@ impl RawReader for IntoIter<KeyPress> { } } -pub struct Sink { - cursor: Rc<Cell<usize>>, // cursor position before last command - last: usize, -} +pub struct Sink {} impl Sink { pub fn new() -> Sink { - Sink { - cursor: Rc::new(Cell::new(0)), - last: 0, - } + Sink {} } } impl Renderer for Sink { - fn move_cursor(&mut self, _: Position, new: Position) -> Result<()> { - self.cursor.replace(self.last); - self.last = new.col; + fn move_cursor(&mut self, _: Position, _: Position) -> Result<()> { Ok(()) } @@ -81,7 +71,6 @@ impl Renderer for Sink { _: usize, ) -> Result<(Position, Position)> { let cursor = self.calculate_position(&line[..line.pos()], prompt_size); - self.last = cursor.col; if let Some(hint) = hint { truncate(&hint, 0, 80); } @@ -124,7 +113,7 @@ pub type Terminal = DummyTerminal; #[derive(Clone, Debug)] pub struct DummyTerminal { pub keys: Vec<KeyPress>, - pub cursor: Rc<Cell<usize>>, // cursor position before last command + pub cursor: usize, // cursor position before last command } impl Term for DummyTerminal { @@ -135,7 +124,7 @@ impl Term for DummyTerminal { fn new() -> DummyTerminal { DummyTerminal { keys: Vec::new(), - cursor: Rc::new(Cell::new(0)), + cursor: 0, } } @@ -160,10 +149,7 @@ impl Term for DummyTerminal { } fn create_writer(&self) -> Sink { - Sink { - cursor: self.cursor.clone(), - last: 0, - } + Sink {} } }