Skip to content

Commit

Permalink
Merge pull request #448 from gwenn/check_cursor_position
Browse files Browse the repository at this point in the history
Disable CPR by default
  • Loading branch information
gwenn authored Oct 11, 2020
2 parents 8f4d899 + 84e2a88 commit caa710c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -162,6 +171,7 @@ impl Default for Config {
color_mode: ColorMode::Enabled,
output_stream: OutputStreamType::Stdout,
tab_stop: 8,
check_cursor_position: false,
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ fn readline_edit<H: Helper>(
}

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();
Expand Down

0 comments on commit caa710c

Please sign in to comment.