Skip to content

Provide Distinct Builder for Reedline #740

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

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
63ccb4b
Configure gitignore for vsc
cactusdualcore Feb 1, 2024
cab3c49
Merge branch 'main' of https://github.com/Cactus-man/reedline into main
cactusdualcore Feb 1, 2024
03faf57
Use actual builder to construct `Reedline`, deprecate builder methods…
cactusdualcore Feb 1, 2024
2dcf5b1
Fixed 'external_printer' feature
cactusdualcore Feb 1, 2024
d09289b
Fixed 'sqlite' feature
cactusdualcore Feb 1, 2024
76b3c9d
Introduce "paste" as a new dep
cactusdualcore Feb 3, 2024
9451daf
Write "with_builder_methods" macro
cactusdualcore Feb 3, 2024
37b71ab
transition least complex case to macro
cactusdualcore Feb 3, 2024
4a0cc5e
add boolean case to macro
cactusdualcore Feb 3, 2024
0179722
transition boolean case to macro
cactusdualcore Feb 3, 2024
a1f1e2b
fix examples
cactusdualcore Feb 3, 2024
22094a2
add generic type case with boxing to macro
cactusdualcore Feb 3, 2024
405e5c7
Fix typo that causes compile error
cactusdualcore Feb 3, 2024
ec327d9
transition generic builder methods to macro
cactusdualcore Feb 3, 2024
e5d0e91
separate macro into distinct ones for clarity
cactusdualcore Feb 3, 2024
dd987cb
Fixed wrong name for method in examples
cactusdualcore Feb 3, 2024
6c7576d
update base reedline version to 0.31
cactusdualcore Apr 15, 2024
e69faae
include new `executing_host_command` field in builder
cactusdualcore Apr 15, 2024
b1bc027
removed macros
cactusdualcore Apr 15, 2024
0383e9c
remove 'paste' dependency as it is no longer needed
cactusdualcore Apr 15, 2024
0cc7039
extract builder-style API into standalone file to reduce clutter
cactusdualcore Apr 15, 2024
94c3171
removed deprecation on builder-style API
cactusdualcore Apr 15, 2024
d483ec0
cleaned the Builder API and the builder-style engine API
cactusdualcore Apr 15, 2024
ff0ef3d
fix doctests
cactusdualcore Apr 15, 2024
029a991
appease the clippy gods
cactusdualcore Apr 15, 2024
0d8da0e
Merge branch 'main' of https://github.com/nushell/reedline
cactusdualcore Apr 30, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -23,3 +23,6 @@ tarpaulin-report.html
*.rsproj
*.rsproj.user
*.sln

# Visual Studio Code
.vscode
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use std::io;

fn main() -> io::Result<()> {
// Create a new Reedline engine with a local History that is not synchronized to a file.
let mut line_editor = Reedline::create();
let mut line_editor = Reedline::new();
let prompt = DefaultPrompt::default();

loop {
13 changes: 7 additions & 6 deletions examples/completions.rs
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ fn main() -> io::Result<()> {
"abadarabc".into(),
];

let completer = Box::new(DefaultCompleter::new_with_wordlen(commands, 2));
let completer = DefaultCompleter::new_with_wordlen(commands, 2);

// Use the interactive menu to select options from the completer
let columnar_menu = ColumnarMenu::default()
@@ -71,12 +71,13 @@ fn main() -> io::Result<()> {
let mut keybindings = default_emacs_keybindings();
add_menu_keybindings(&mut keybindings);

let edit_mode = Box::new(Emacs::new(keybindings));
let edit_mode = Emacs::new(keybindings);

let mut line_editor = Reedline::create()
.with_completer(completer)
.with_menu(ReedlineMenu::EngineCompleter(completion_menu))
.with_edit_mode(edit_mode);
let mut line_editor = Reedline::builder()
.with_completions(completer)
.add_menu(ReedlineMenu::EngineCompleter(completion_menu))
.with_edit_mode(edit_mode)
.build();

let prompt = DefaultPrompt::default();

2 changes: 1 addition & 1 deletion examples/custom_prompt.rs
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ impl Prompt for CustomPrompt {

fn main() -> io::Result<()> {
println!("Custom prompt demo:\nAbort with Ctrl-C or Ctrl-D");
let mut line_editor = Reedline::create();
let mut line_editor = Reedline::new();

let prompt = CustomPrompt(Cell::new(0), "Custom Prompt");

13 changes: 7 additions & 6 deletions examples/cwd_aware_hinter.rs
Original file line number Diff line number Diff line change
@@ -25,12 +25,12 @@ fn create_item(cwd: &str, cmd: &str, exit_status: i64) -> reedline::HistoryItem
}
}

fn create_filled_example_history(home_dir: &str, orig_dir: &str) -> Box<dyn reedline::History> {
fn create_filled_example_history(home_dir: &str, orig_dir: &str) -> impl reedline::History {
use reedline::History;
#[cfg(not(any(feature = "sqlite", feature = "sqlite-dynlib")))]
let mut history = Box::new(reedline::FileBackedHistory::new(100));
#[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))]
let mut history = Box::new(reedline::SqliteBackedHistory::in_memory().unwrap());
let mut history = reedline::SqliteBackedHistory::in_memory().unwrap();

history.save(create_item(orig_dir, "dummy", 0)).unwrap(); // add dummy item so ids start with 1
history.save(create_item(orig_dir, "ls /usr", 0)).unwrap();
@@ -56,11 +56,12 @@ fn main() -> io::Result<()> {
orig_dir.to_string_lossy().as_ref(),
);

let mut line_editor = Reedline::create()
.with_hinter(Box::new(
let mut line_editor = Reedline::builder()
.with_hints(
CwdAwareHinter::default().with_style(Style::new().bold().italic().fg(Color::Yellow)),
))
.with_history(history);
)
.with_history(history)
.build();

let prompt = DefaultPrompt::default();

66 changes: 29 additions & 37 deletions examples/demo.rs
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ use {
reedline::{
default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings,
ColumnarMenu, DefaultCompleter, DefaultHinter, DefaultPrompt, DefaultValidator,
EditCommand, EditMode, Emacs, ExampleHighlighter, Keybindings, ListMenu, Reedline,
ReedlineEvent, ReedlineMenu, Signal, Vi,
EditCommand, Emacs, ExampleHighlighter, Keybindings, ListMenu, Reedline, ReedlineEvent,
ReedlineMenu, Signal, Vi,
},
};

@@ -33,16 +33,14 @@ fn main() -> reedline::Result<()> {
};

#[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))]
let history = Box::new(
reedline::SqliteBackedHistory::with_file(
"history.sqlite3".into(),
history_session_id,
Some(chrono::Utc::now()),
)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?,
);
let history = reedline::SqliteBackedHistory::with_file(
"history.sqlite3".into(),
history_session_id,
Some(chrono::Utc::now()),
)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
#[cfg(not(any(feature = "sqlite", feature = "sqlite-dynlib")))]
let history = Box::new(FileBackedHistory::with_file(50, "history.txt".into())?);
let history = FileBackedHistory::with_file(50, "history.txt".into())?;
let commands = vec![
"test".into(),
"clear".into(),
@@ -71,41 +69,38 @@ fn main() -> reedline::Result<()> {
"こんにちは世界".into(),
"こんばんは世界".into(),
];
let completer = Box::new(DefaultCompleter::new_with_wordlen(commands.clone(), 2));
let completer = DefaultCompleter::new_with_wordlen(commands.clone(), 2);

let cursor_config = CursorConfig {
vi_insert: Some(SetCursorStyle::BlinkingBar),
vi_normal: Some(SetCursorStyle::SteadyBlock),
emacs: None,
};

let mut line_editor = Reedline::create()
.with_history_session_id(history_session_id)
let mut builder = Reedline::builder()
.with_history_session_id(history_session_id.unwrap())
.with_history(history)
.with_history_exclusion_prefix(Some(" ".to_string()))
.with_completer(completer)
.with_quick_completions(true)
.with_partial_completions(true)
.with_history_exclusion_prefix(" ".to_string())
.with_completions(completer)
.use_quick_completions(true)
.use_partial_completions(true)
.with_cursor_config(cursor_config)
.use_bracketed_paste(true)
.use_kitty_keyboard_enhancement(true)
.with_highlighter(Box::new(ExampleHighlighter::new(commands)))
.with_hinter(Box::new(
DefaultHinter::default().with_style(Style::new().fg(Color::DarkGray)),
))
.with_validator(Box::new(DefaultValidator))
.with_ansi_colors(true);
.with_highlighter(ExampleHighlighter::new(commands))
.with_hints(DefaultHinter::default().with_style(Style::new().fg(Color::DarkGray)))
.with_validator(DefaultValidator)
.use_ansi_colors(true);

// Adding default menus for the compiled reedline
line_editor = line_editor
.with_menu(ReedlineMenu::EngineCompleter(Box::new(
builder = builder.add_menus(vec![
ReedlineMenu::EngineCompleter(Box::new(
ColumnarMenu::default().with_name("completion_menu"),
)))
.with_menu(ReedlineMenu::HistoryMenu(Box::new(
ListMenu::default().with_name("history_menu"),
)));
)),
ReedlineMenu::HistoryMenu(Box::new(ListMenu::default().with_name("history_menu"))),
]);

let edit_mode: Box<dyn EditMode> = if vi_mode {
if vi_mode {
let mut normal_keybindings = default_vi_normal_keybindings();
let mut insert_keybindings = default_vi_insert_keybindings();

@@ -114,22 +109,19 @@ fn main() -> reedline::Result<()> {

add_newline_keybinding(&mut insert_keybindings);

Box::new(Vi::new(insert_keybindings, normal_keybindings))
builder = builder.with_edit_mode(Vi::new(insert_keybindings, normal_keybindings));
} else {
let mut keybindings = default_emacs_keybindings();
add_menu_keybindings(&mut keybindings);
add_newline_keybinding(&mut keybindings);

Box::new(Emacs::new(keybindings))
builder = builder.with_edit_mode(Emacs::new(keybindings));
};

line_editor = line_editor.with_edit_mode(edit_mode);

// Adding vi as text editor
let temp_file = temp_dir().join("temp_file.nu");
let mut command = Command::new("vi");
command.arg(&temp_file);
line_editor = line_editor.with_buffer_editor(command, temp_file);
let mut line_editor = builder.with_buffer_editor(command, temp_file).build();

let prompt = DefaultPrompt::default();

2 changes: 1 addition & 1 deletion examples/external_printer.rs
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ fn main() {
}
});

let mut line_editor = Reedline::create().with_external_printer(printer);
let mut line_editor = Reedline::builder().with_external_printer(printer).build();
let prompt = DefaultPrompt::default();

loop {
5 changes: 3 additions & 2 deletions examples/highlighter.rs
Original file line number Diff line number Diff line change
@@ -12,8 +12,9 @@ fn main() -> io::Result<()> {
"hello world reedline".into(),
"this is the reedline crate".into(),
];
let mut line_editor =
Reedline::create().with_highlighter(Box::new(ExampleHighlighter::new(commands)));
let mut line_editor = Reedline::builder()
.with_highlighter(ExampleHighlighter::new(commands))
.build();
let prompt = DefaultPrompt::default();

loop {
6 changes: 3 additions & 3 deletions examples/hinter.rs
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@ use reedline::{DefaultHinter, DefaultPrompt, Reedline, Signal};
use std::io;

fn main() -> io::Result<()> {
let mut line_editor = Reedline::create().with_hinter(Box::new(
DefaultHinter::default().with_style(Style::new().italic().fg(Color::LightGray)),
));
let mut line_editor = Reedline::builder()
.with_hints(DefaultHinter::default().with_style(Style::new().italic().fg(Color::LightGray)))
.build();
let prompt = DefaultPrompt::default();

loop {
8 changes: 3 additions & 5 deletions examples/history.rs
Original file line number Diff line number Diff line change
@@ -10,12 +10,10 @@ use reedline::{DefaultPrompt, FileBackedHistory, Reedline, Signal};
use std::io;

fn main() -> io::Result<()> {
let history = Box::new(
FileBackedHistory::with_file(5, "history.txt".into())
.expect("Error configuring history with file"),
);
let history = FileBackedHistory::with_file(5, "history.txt".into())
.expect("Error configuring history with file");

let mut line_editor = Reedline::create().with_history(history);
let mut line_editor = Reedline::builder().with_history(history).build();
let prompt = DefaultPrompt::default();

loop {
13 changes: 7 additions & 6 deletions examples/ide_completions.rs
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ fn main() -> io::Result<()> {
"abadarabc".into(),
];

let completer = Box::new(DefaultCompleter::new_with_wordlen(commands, 2));
let completer = DefaultCompleter::new_with_wordlen(commands, 2);

// Use the interactive menu to select options from the completer
let mut ide_menu = IdeMenu::default()
@@ -107,12 +107,13 @@ fn main() -> io::Result<()> {
let mut keybindings = default_emacs_keybindings();
add_menu_keybindings(&mut keybindings);

let edit_mode = Box::new(Emacs::new(keybindings));
let edit_mode = Emacs::new(keybindings);

let mut line_editor = Reedline::create()
.with_completer(completer)
.with_menu(ReedlineMenu::EngineCompleter(completion_menu))
.with_edit_mode(edit_mode);
let mut line_editor = Reedline::builder()
.with_completions(completer)
.add_menu(ReedlineMenu::EngineCompleter(completion_menu))
.with_edit_mode(edit_mode)
.build();

let prompt = DefaultPrompt::default();

30 changes: 15 additions & 15 deletions examples/transient_prompt.rs
Original file line number Diff line number Diff line change
@@ -89,31 +89,31 @@ fn main() -> io::Result<()> {
"hello world reedline".into(),
"this is the reedline crate".into(),
];
let completer = Box::new(DefaultCompleter::new_with_wordlen(commands.clone(), 2));
let completer = DefaultCompleter::new_with_wordlen(commands.clone(), 2);
// Use the interactive menu to select options from the completer
let completion_menu = Box::new(ColumnarMenu::default().with_name("completion_menu"));

let mut keybindings = default_emacs_keybindings();
add_menu_keybindings(&mut keybindings);

let edit_mode = Box::new(Emacs::new(keybindings));
let edit_mode = Emacs::new(keybindings);

let mut line_editor = Reedline::create()
.with_hinter(Box::new(
DefaultHinter::default().with_style(Style::new().fg(Color::LightGray)),
))
.with_completer(completer)
.with_menu(ReedlineMenu::EngineCompleter(completion_menu))
#[allow(unused_mut)]
let mut builder = Reedline::builder()
.with_hints(DefaultHinter::default().with_style(Style::new().fg(Color::LightGray)))
.with_completions(completer)
.add_menu(ReedlineMenu::EngineCompleter(completion_menu))
.with_edit_mode(edit_mode)
.with_highlighter(Box::new(ExampleHighlighter::new(commands)))
.with_validator(Box::new(CustomValidator {}))
.with_ansi_colors(true)
.with_history_exclusion_prefix(Some(String::from(" ")))
.with_transient_prompt(Box::new(TransientPrompt {}));
.with_highlighter(ExampleHighlighter::new(commands))
.with_validator(CustomValidator {})
.use_ansi_colors(true)
.with_history_exclusion_prefix(String::from(" "))
.with_transient_prompt(TransientPrompt {});
#[cfg(any(feature = "sqlite", feature = "sqlite-dynlib"))]
{
line_editor = line_editor.with_history(Box::new(SqliteBackedHistory::in_memory().unwrap()));
}
builder = builder.with_history(SqliteBackedHistory::in_memory().unwrap());
};
let mut line_editor = builder.build();

let prompt = DefaultPrompt::default();

6 changes: 4 additions & 2 deletions examples/validator.rs
Original file line number Diff line number Diff line change
@@ -21,8 +21,10 @@ impl Validator for CustomValidator {
}

fn main() -> io::Result<()> {
println!("Input \"complete\" followed by [Enter], will accept the input line (Signal::Succeed will be called)\nPressing [Enter] will in other cases give you a multi-line prompt.\nAbort with Ctrl-C or Ctrl-D");
let mut line_editor = Reedline::create().with_validator(Box::new(CustomValidator));
println!("Input \"complete\" followed by [Enter], will accept the input line (Signal::Succeed will be called)");
println!("Pressing [Enter] will in other cases give you a multi-line prompt.");
println!("Abort with Ctrl-C or Ctrl-D");
let mut line_editor = Reedline::builder().with_validator(CustomValidator).build();

let prompt = DefaultPrompt::default();

4 changes: 2 additions & 2 deletions src/completion/default.rs
Original file line number Diff line number Diff line change
@@ -18,9 +18,9 @@ use std::{
/// "hello world reedline".into(),
/// "this is the reedline crate".into(),
/// ];
/// let completer = Box::new(DefaultCompleter::new_with_wordlen(commands.clone(), 2));
/// let completer = DefaultCompleter::new_with_wordlen(commands.clone(), 2);
///
/// let mut line_editor = Reedline::create().with_completer(completer);
/// let mut line_editor = Reedline::builder().with_completions(completer).build();
/// ```
#[derive(Debug, Clone)]
pub struct DefaultCompleter {
501 changes: 101 additions & 400 deletions src/engine.rs

Large diffs are not rendered by default.

427 changes: 427 additions & 0 deletions src/engine/builder.rs

Large diffs are not rendered by default.

166 changes: 166 additions & 0 deletions src/engine/inspection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
use std::{path::PathBuf, process};

use nu_ansi_term::Style;

use crate::*;

impl super::Reedline {
/// Set the [`History`](crate::History) of a constructed engine.
/// Prefer [`ReedlineBuilder::with_history`](crate::engine::builder::ReedlineBuilder::with_history)
/// if you don't need to change this while using reedline.
pub fn with_history(&mut self, history: Box<dyn History>) -> &mut Self {
self.history = history;
self
}

/// Set the [`Hinter`](crate::Hinter) of a constructed engine.
/// Prefer [`ReedlineBuilder::with_hints`](crate::engine::builder::ReedlineBuilder::with_hints)
/// if you don't need to change this while using reedline.
pub fn with_hints(&mut self, hints: Option<Box<dyn Hinter>>) -> &mut Self {
self.hinter = hints;
self
}

/// Set the [`Completer`](crate::Completer) of a constructed engine.
/// Prefer [`ReedlineBuilder::with_completions`](crate::engine::builder::ReedlineBuilder::with_completions)
/// if you don't need to change this while using reedline.
pub fn with_completions(&mut self, completions: Box<dyn Completer>) -> &mut Self {
self.completer = completions;
self
}

/// Set the [`Highlighter`](crate::Highlighter) of a constructed engine.
/// Prefer [`ReedlineBuilder::with_highlighter`](crate::engine::builder::ReedlineBuilder::with_highlighter)
/// if you don't need to change this while using reedline.
pub fn with_highlighter(&mut self, highlighter: Box<dyn Highlighter>) -> &mut Self {
self.highlighter = highlighter;
self
}

/// Set the [`Validator`](crate::Validator) of a constructed engine.
/// Prefer [`ReedlineBuilder::with_validator`](crate::engine::builder::ReedlineBuilder::with_validator)
/// if you don't need to change this while using reedline.
pub fn with_validator(&mut self, validator: Option<Box<dyn Validator>>) -> &mut Self {
self.validator = validator;
self
}

/// Use a [`Prompt`](crate::Prompt) as the the transient prompt of a constructed engine.
/// Prefer [`ReedlineBuilder::with_transient_prompt`](crate::engine::builder::ReedlineBuilder::with_transient_prompt)
/// if you don't need to change this while using reedline.
pub fn with_transient_prompt(&mut self, prompt: Option<Box<dyn Prompt>>) -> &mut Self {
self.transient_prompt = prompt;
self
}

/// Set the edit mode of a constructed engine.
/// Prefer [`ReedlineBuilder::with_edit_mode`](crate::engine::builder::ReedlineBuilder::with_edit_mode)
/// if you don't need to change this while using reedline.
pub fn with_edit_mode(&mut self, edit_mode: Box<dyn EditMode>) -> &mut Self {
self.edit_mode = edit_mode;
self
}

/// Set the history exclusion prefix of a construncted engine.
/// Prefer [`ReedlineBuilder::with_history_exclusion_prefix`](crate::engine::builder::ReedlineBuilder::with_history_exclusion_prefix)
/// if you don't need to change this while using reedline.
pub fn with_history_exclusion_prefix(&mut self, ignore_prefix: Option<String>) -> &mut Self {
self.history_exclusion_prefix = ignore_prefix;
self
}

/// Set the visual selection style of a construncted engine.
/// Prefer [`ReedlineBuilder::with_selection_style`](crate::engine::builder::ReedlineBuilder::with_selection_style)
/// if you don't need to change this while using reedline.
pub fn with_selection_style(&mut self, selection_style: Style) -> &mut Self {
self.visual_selection_style = selection_style;
self
}

/// Configure the cursor shapes depending on the edit mode.
/// Prefer [`ReedlineBuilder::with_cursor_config`](crate::engine::builder::ReedlineBuilder::with_cursor_config)
/// if you don't need to change this while using reedline.
pub fn with_cursor_config(&mut self, cursor_config: Option<CursorConfig>) -> &mut Self {
self.cursor_shapes = cursor_config;
self
}

/// Set the history session id.
/// Prefer [`ReedlineBuilder::with_history_session_id`](crate::engine::builder::ReedlineBuilder::with_history_session_id)
/// if you don't need to change this while using reedline.
pub fn with_history_session_id(&mut self, session: Option<HistorySessionId>) {
self.history_session_id = session;
}

/// The history session id, or [`None`](Option::None) if no session is attached.
pub fn history_session_id(&self) -> Option<HistorySessionId> {
self.history_session_id
}

/// Set whether to use quick completions.
/// Prefer [`ReedlineBuilder::use_quick_completions`](crate::engine::builder::ReedlineBuilder::use_quick_completions)
/// if you don't need to change this while using reedline.
pub fn use_quick_completions(&mut self, enabled: bool) -> &mut Self {
self.quick_completions = enabled;
self
}

/// Set whether to use partial completions.
/// Prefer [`ReedlineBuilder::use_partial_completions`](crate::engine::builder::ReedlineBuilder::use_partial_completions)
/// if you don't need to change this while using reedline.
pub fn use_partial_completions(&mut self, enabled: bool) -> &mut Self {
self.partial_completions = enabled;
self
}

/// Set whether to use bracketed paste.
/// Prefer [`ReedlineBuilder::use_bracketed_paste`](crate::engine::builder::ReedlineBuilder::use_bracketed_paste)
/// if you don't need to change this while using reedline.
pub fn use_bracketed_paste(&mut self, enabled: bool) -> &mut Self {
self.bracketed_paste.set(enabled);
self
}

/// Set whether to use the enhanced keyboard protocol.
/// Prefer [`ReedlineBuilder::use_kitty_keyboard_enhancement`](crate::engine::builder::ReedlineBuilder::use_kitty_keyboard_enhancement)
/// if you don't need to change this while using reedline.
pub fn use_kitty_keyboard_enhancement(&mut self, enabled: bool) -> &mut Self {
self.kitty_protocol.set(enabled);
self
}

/// Set whether ANSI escape sequences should be used to provide colored terminal output.
/// Prefer [`ReedlineBuilder::use_ansi_colors`](crate::engine::builder::ReedlineBuilder::use_ansi_colors)
/// if you don't need to change this while using reedline.
pub fn use_ansi_colors(&mut self, enabled: bool) -> &mut Self {
self.use_ansi_coloring = enabled;
self
}

/// Add a menu.
/// Prefer [`ReedlineBuilder::add_menu`](crate::engine::builder::ReedlineBuilder::add_menu)
/// if you don't need to add a menu while using reedline.
pub fn add_menu(&mut self, menu: ReedlineMenu) -> &mut Self {
self.menus.push(menu);
self
}

/// Allow the line buffer to be edited through a ephemeral file at the given path with the specified editor.
/// Prefer [`ReedlineBuilder::with_buffer_editor`](crate::engine::builder::ReedlineBuilder::with_buffer_editor)
/// if you don't need to change this while using reedline.
pub fn with_buffer_editor(
&mut self,
editor: process::Command,
temp_file: PathBuf,
) -> &mut Self {
let mut editor = editor;
if !editor.get_args().any(|arg| arg == temp_file.as_os_str()) {
editor.arg(&temp_file);
}
self.buffer_editor = Some(super::BufferEditor {
command: editor,
temp_file,
});
self
}
}
21 changes: 10 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@
//! "hello world reedline".into(),
//! "this is the reedline crate".into(),
//! ];
//! let completer = Box::new(DefaultCompleter::new_with_wordlen(commands.clone(), 2));
//! let completer = DefaultCompleter::new_with_wordlen(commands.clone(), 2);
//! // Use the interactive menu to select options from the completer
//! let completion_menu = Box::new(ColumnarMenu::default().with_name("completion_menu"));
//! // Set up the required keybindings
@@ -118,12 +118,13 @@
//! ]),
//! );
//!
//! let edit_mode = Box::new(Emacs::new(keybindings));
//! let edit_mode = Emacs::new(keybindings);
//!
//! let mut line_editor = Reedline::create()
//! .with_completer(completer)
//! .with_menu(ReedlineMenu::EngineCompleter(completion_menu))
//! .with_edit_mode(edit_mode);
//! let mut line_editor = Reedline::builder()
//! .with_completions(completer)
//! .add_menu(ReedlineMenu::EngineCompleter(completion_menu))
//! .with_edit_mode(edit_mode)
//! .build();
//! ```
//!
//! ## Integrate with [`Hinter`] for fish-style history autosuggestions
@@ -141,10 +142,10 @@
//! };
//!
//!
//! let mut line_editor = Reedline::create().with_hinter(Box::new(
//! let mut line_editor = Reedline::builder().with_hints(
//! DefaultHinter::default()
//! .with_style(Style::new().italic().fg(Color::LightGray)),
//! ));
//! );
//! ```
//!
//!
@@ -155,9 +156,7 @@
//!
//! use reedline::{DefaultValidator, Reedline};
//!
//! let validator = Box::new(DefaultValidator);
//!
//! let mut line_editor = Reedline::create().with_validator(validator);
//! let mut line_editor = Reedline::builder().with_validator(DefaultValidator).build();
//! ```
//!
//! ## Use custom [`EditMode`]