From 84e2a88c8ba7ae90dd3b8f6965512d8e6d5369ea Mon Sep 17 00:00:00 2001 From: gwenn Date: Sun, 4 Oct 2020 09:32:20 +0200 Subject: [PATCH] Disable CPR by default --- src/config.rs | 25 +++++++++++++++++++++++++ src/lib.rs | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 08aaa9882f..ff9881f331 100644 --- a/src/config.rs +++ b/src/config.rs @@ -28,6 +28,8 @@ pub struct Config { output_stream: OutputStreamType, /// Horizontal space taken by a tab. tab_stop: usize, + /// Check if cursor position is at leftmost before displaying prompt + check_cursor_position: bool, } impl Config { @@ -145,6 +147,13 @@ impl Config { pub(crate) fn set_tab_stop(&mut self, tab_stop: usize) { self.tab_stop = tab_stop; } + + /// Check if cursor position is at leftmost before displaying prompt. + /// + /// By default, we don't check. + pub fn check_cursor_position(&self) -> bool { + self.check_cursor_position + } } impl Default for Config { @@ -162,6 +171,7 @@ impl Default for Config { color_mode: ColorMode::Enabled, output_stream: OutputStreamType::Stdout, tab_stop: 8, + check_cursor_position: false, } } } @@ -357,6 +367,14 @@ impl Builder { self } + /// Check if cursor position is at leftmost before displaying prompt. + /// + /// By default, we don't check. + pub fn check_cursor_position(mut self, yes: bool) -> Self { + self.set_check_cursor_position(yes); + self + } + /// Builds a `Config` with the settings specified so far. pub fn build(self) -> Config { self.p @@ -451,4 +469,11 @@ pub trait Configurer { fn set_tab_stop(&mut self, tab_stop: usize) { self.config_mut().set_tab_stop(tab_stop); } + + /// Check if cursor position is at leftmost before displaying prompt. + /// + /// By default, we don't check. + fn set_check_cursor_position(&mut self, yes: bool) { + self.config_mut().check_cursor_position = yes; + } } diff --git a/src/lib.rs b/src/lib.rs index 018007663d..c4ed5bb48c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -439,7 +439,7 @@ fn readline_edit( } let mut rdr = editor.term.create_reader(&editor.config)?; - if editor.term.is_output_tty() { + if editor.term.is_output_tty() && editor.config.check_cursor_position() { if let Err(e) = s.move_cursor_at_leftmost(&mut rdr) { if s.out.sigwinch() { s.out.update_size();