Skip to content

Commit aecbf41

Browse files
authored
Merge pull request kkawakam#710 from segeljakt/derive-default-history-hinter
Add `HistoryHinter::default()` and `HistoryHinter::new()`
2 parents 23cb8a1 + 71c2316 commit aecbf41

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

examples/custom_key_bindings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl ConditionalEventHandler for TabEventHandler {
8787

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

9292
let ceh = Box::new(CompleteHintHandler);
9393
rl.bind_sequence(KeyEvent::ctrl('E'), EventHandler::Conditional(ceh.clone()));

examples/example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn main() -> rustyline::Result<()> {
5858
let h = MyHelper {
5959
completer: FilenameCompleter::new(),
6060
highlighter: MatchingBracketHighlighter::new(),
61-
hinter: HistoryHinter {},
61+
hinter: HistoryHinter::new(),
6262
colored_prompt: "".to_owned(),
6363
validator: MatchingBracketValidator::new(),
6464
};

src/hint.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,16 @@ impl<'r, H: ?Sized + Hinter> Hinter for &'r H {
5050

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

56+
impl HistoryHinter {
57+
/// Create a new `HistoryHinter`
58+
pub fn new() -> HistoryHinter {
59+
HistoryHinter::default()
60+
}
61+
}
62+
5563
impl Hinter for HistoryHinter {
5664
type Hint = String;
5765

0 commit comments

Comments
 (0)