Skip to content

Commit

Permalink
Merge pull request #710 from segeljakt/derive-default-history-hinter
Browse files Browse the repository at this point in the history
Add `HistoryHinter::default()` and `HistoryHinter::new()`
  • Loading branch information
gwenn authored Jun 26, 2023
2 parents 23cb8a1 + 71c2316 commit aecbf41
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/custom_key_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl ConditionalEventHandler for TabEventHandler {

fn main() -> Result<()> {
let mut rl = Editor::<MyHelper, DefaultHistory>::new()?;
rl.set_helper(Some(MyHelper(HistoryHinter {})));
rl.set_helper(Some(MyHelper(HistoryHinter::new())));

let ceh = Box::new(CompleteHintHandler);
rl.bind_sequence(KeyEvent::ctrl('E'), EventHandler::Conditional(ceh.clone()));
Expand Down
2 changes: 1 addition & 1 deletion examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main() -> rustyline::Result<()> {
let h = MyHelper {
completer: FilenameCompleter::new(),
highlighter: MatchingBracketHighlighter::new(),
hinter: HistoryHinter {},
hinter: HistoryHinter::new(),
colored_prompt: "".to_owned(),
validator: MatchingBracketValidator::new(),
};
Expand Down
8 changes: 8 additions & 0 deletions src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ impl<'r, H: ?Sized + Hinter> Hinter for &'r H {

/// Add suggestion based on previous history entries matching current user
/// input.
#[derive(Default)]
pub struct HistoryHinter {}

impl HistoryHinter {
/// Create a new `HistoryHinter`
pub fn new() -> HistoryHinter {
HistoryHinter::default()
}
}

impl Hinter for HistoryHinter {
type Hint = String;

Expand Down

0 comments on commit aecbf41

Please sign in to comment.