-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added complter, removed reedline crate
- Loading branch information
1 parent
6fb8f86
commit e7fefce
Showing
3 changed files
with
35 additions
and
209 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::sync::LazyLock; | ||
|
||
use color_eyre::eyre; | ||
use dialoguer::{Completion, Input}; | ||
use magic_wormhole::wordlist::{default_wordlist, Wordlist}; | ||
|
||
static WORDLIST: LazyLock<Wordlist> = LazyLock::new(|| default_wordlist(2)); | ||
|
||
struct CustomCompletion {} | ||
|
||
impl CustomCompletion { | ||
pub fn default() -> Self { | ||
CustomCompletion {} | ||
} | ||
} | ||
|
||
impl Completion for CustomCompletion { | ||
fn get(&self, input: &str) -> Option<String> { | ||
WORDLIST.get_completions(input).first().cloned() | ||
} | ||
} | ||
|
||
pub fn enter_code() -> eyre::Result<String> { | ||
let custom_completion = CustomCompletion::default(); | ||
|
||
Input::new() | ||
.with_prompt("Wormhole Code") | ||
.completion_with(&custom_completion) | ||
.interact_text() | ||
.map_err(From::from) | ||
} |