Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable newline after every command #756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct Config {
check_cursor_position: bool,
/// Bracketed paste on unix platform
enable_bracketed_paste: bool,
/// Write new line after accepting prompt input
enable_newline: bool,
}

impl Config {
Expand Down Expand Up @@ -193,6 +195,14 @@ impl Config {
pub fn enable_bracketed_paste(&self) -> bool {
self.enable_bracketed_paste
}

/// Write new line after accepting prompt input
///
/// By default, it's enabled.
#[must_use]
pub fn enable_newline(&self) -> bool {
self.enable_newline
}
}

impl Default for Config {
Expand All @@ -213,6 +223,7 @@ impl Default for Config {
indent_size: 2,
check_cursor_position: false,
enable_bracketed_paste: true,
enable_newline: true,
}
}
}
Expand Down Expand Up @@ -450,6 +461,15 @@ impl Builder {
self
}

/// Enable or disable newline after accepting prompt input
///
/// By default, it's enabled.
#[must_use]
pub fn newline(mut self, enabled: bool) -> Self {
self.enable_newline(enabled);
self
}

/// Builds a `Config` with the settings specified so far.
#[must_use]
pub fn build(self) -> Config {
Expand Down Expand Up @@ -567,4 +587,11 @@ pub trait Configurer {
fn enable_bracketed_paste(&mut self, enabled: bool) {
self.config_mut().enable_bracketed_paste = enabled;
}

/// Enable or disable newline after accepting prompt input
///
/// By default, it's enabled.
fn enable_newline(&mut self, enabled: bool) {
self.config_mut().enable_newline = enabled;
}
}
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@ impl<H: Helper, I: History> Editor<H, I> {
}
}
drop(guard); // disable_raw_mode(original_mode)?;
self.term.writeln()?;
if self.config.enable_newline() {
self.term.writeln()?;
}
user_input
} else {
debug!(target: "rustyline", "stdin is not a tty");
Expand Down