From ec02d667f0f0dbb00c57ee787ab90484e993f482 Mon Sep 17 00:00:00 2001 From: Elias Dalbeck Date: Wed, 25 Sep 2024 16:21:17 +0200 Subject: [PATCH 1/3] wormhole code validation length check --- cli/src/reedline.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cli/src/reedline.rs b/cli/src/reedline.rs index dce86272..e21ae1cb 100644 --- a/cli/src/reedline.rs +++ b/cli/src/reedline.rs @@ -147,6 +147,11 @@ impl CodeHighliter { return false; } + // Minimum code length + if parts.len() < 3 { + return false; + } + // Check all words for validity parts.iter().skip(1).all(|&word| { WORDLIST From bd19d093e73ee026d6a6e58210ccfcd5821cb2a4 Mon Sep 17 00:00:00 2001 From: Elias Dalbeck Date: Mon, 7 Oct 2024 19:49:02 +0200 Subject: [PATCH 2/3] removed code highlighting because of custom wordlists --- Cargo.lock | 1 - cli/Cargo.toml | 1 - cli/src/reedline.rs | 56 +++------------------------------------------ 3 files changed, 3 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba4489b4..81e32c84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1857,7 +1857,6 @@ dependencies = [ "fuzzt", "indicatif", "magic-wormhole", - "nu-ansi-term 0.50.1", "number_prefix", "qr2term", "rand", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 7d22b846..ec860ffa 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -44,7 +44,6 @@ arboard = { optional = true, workspace = true, features = [ tracing = { workspace = true, features = ["log", "log-always"] } tracing-subscriber = { workspace = true, features = ["env-filter"] } reedline = "0.35.0" -nu-ansi-term = "0.50.1" fuzzt = "0.3.1" [dev-dependencies] diff --git a/cli/src/reedline.rs b/cli/src/reedline.rs index 62673b96..8f3a27af 100644 --- a/cli/src/reedline.rs +++ b/cli/src/reedline.rs @@ -3,11 +3,10 @@ use std::{borrow::Cow, sync::LazyLock}; use color_eyre::eyre::{self, bail}; use fuzzt::{algorithms::JaroWinkler, get_top_n}; use magic_wormhole::wordlist::default_wordlist_flatned; -use nu_ansi_term::{Color, Style}; use reedline::{ - default_emacs_keybindings, ColumnarMenu, Completer, Emacs, Highlighter, KeyCode, KeyModifiers, - MenuBuilder, Prompt, PromptEditMode, PromptHistorySearch, Reedline, ReedlineEvent, - ReedlineMenu, Signal, Span, StyledText, Suggestion, + default_emacs_keybindings, ColumnarMenu, Completer, Emacs, KeyCode, KeyModifiers, MenuBuilder, + Prompt, PromptEditMode, PromptHistorySearch, Reedline, ReedlineEvent, ReedlineMenu, Signal, + Span, Suggestion, }; static WORDLIST: LazyLock> = LazyLock::new(|| default_wordlist_flatned()); @@ -117,54 +116,6 @@ impl Completer for CodeCompleter { } } -struct CodeHighliter {} - -impl CodeHighliter { - fn default() -> Self { - CodeHighliter {} - } - - fn is_valid_code(&self, code: &str) -> bool { - let parts: Vec<&str> = code.split('-').collect(); - - // If the first element in code is not a valid number - if !parts - .first() - .and_then(|c| c.parse::().ok()) - .is_some_and(|c| (0..1000).contains(&c)) - { - return false; - } - - // Minimum code length - if parts.len() < 3 { - return false; - } - - // Check all words for validity - parts - .iter() - .skip(1) - .all(|&word| WORDLIST.iter().any(|valid_word| valid_word == word)) - } -} - -impl Highlighter for CodeHighliter { - fn highlight(&self, line: &str, _cursor: usize) -> StyledText { - let invalid = Style::new().fg(Color::Red).bold(); - let valid = Style::new().fg(Color::Green).bold(); - - let style = match self.is_valid_code(line) { - true => valid, - false => invalid, - }; - - let mut t = StyledText::new(); - t.push((style, line.to_string())); - t - } -} - pub fn enter_code() -> eyre::Result { // Set up the required keybindings let mut keybindings = default_emacs_keybindings(); @@ -184,7 +135,6 @@ pub fn enter_code() -> eyre::Result { let mut line_editor = Reedline::create() .with_completer(Box::new(CodeCompleter::default())) - .with_highlighter(Box::new(CodeHighliter::default())) .with_menu(ReedlineMenu::EngineCompleter(completion_menu)) .with_quick_completions(true) .with_edit_mode(edit_mode); From 0e349cd1b81b99169f435b5bbf867136abb52b97 Mon Sep 17 00:00:00 2001 From: Elias Dalbeck Date: Mon, 7 Oct 2024 19:56:05 +0200 Subject: [PATCH 3/3] rust version 1.81 for LazyLock support --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 03881e2e..3665b0a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ homepage = "http://magic-wormhole.io/" repository = "https://github.com/magic-wormhole/magic-wormhole.rs/tree/main/cli" license = "EUPL-1.2" -rust-version = "1.75" +rust-version = "1.81" edition = "2021" [workspace.dependencies]