-
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.
Tab completion and syntax checking (#261)
- Loading branch information
1 parent
1195b8a
commit 83cbe0e
Showing
8 changed files
with
156 additions
and
77 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
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) | ||
} |
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
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