summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgwenn <45554+gwenn@users.noreply.github.com>2023-06-26 07:35:28 +0200
committerGitHub <noreply@github.com>2023-06-26 07:35:28 +0200
commitaecbf41252b22c4e19785342073c5695a56c4d2b (patch)
tree3d774341235c0020be2aebd95a6efdc153869030
parent23cb8a16135dd885a356cc243d3a8cd0da0ef0e6 (diff)
parent71c2316abb591a033fd36b7e802203d690db2128 (diff)
downloadrustyline-aecbf41252b22c4e19785342073c5695a56c4d2b.zip
Merge pull request #710 from segeljakt/derive-default-history-hinter
Add `HistoryHinter::default()` and `HistoryHinter::new()`
-rw-r--r--examples/custom_key_bindings.rs2
-rw-r--r--examples/example.rs2
-rw-r--r--src/hint.rs8
3 files changed, 10 insertions, 2 deletions
diff --git a/examples/custom_key_bindings.rs b/examples/custom_key_bindings.rs
index 3fa4519..78db874 100644
--- a/examples/custom_key_bindings.rs
+++ b/examples/custom_key_bindings.rs
@@ -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()));
diff --git a/examples/example.rs b/examples/example.rs
index fc53106..8ed975b 100644
--- a/examples/example.rs
+++ b/examples/example.rs
@@ -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(),
};
diff --git a/src/hint.rs b/src/hint.rs
index ea28ca8..1b4f88a 100644
--- a/src/hint.rs
+++ b/src/hint.rs
@@ -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;