From b1d182229ca034cd695b16dee42329a9437a3b63 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Wed, 18 Sep 2024 17:18:12 +0800 Subject: [PATCH] Update rustyline Signed-off-by: Eval EXEC --- .github/workflows/ci.yaml | 2 +- Cargo.lock | 2 +- deny.toml | 10 ++++++++++ src/interactive.rs | 31 +++++++++++++++++-------------- src/utils/completer.rs | 14 +++++++------- test/src/spec/udt/mod.rs | 8 ++++---- 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 14f19377..accd3bab 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -71,7 +71,7 @@ jobs: strategy: matrix: checks: - - --hide-inclusion-graph --show-stats advisories sources + - --hide-inclusion-graph --show-stats advisories sources -Wunmaintained - --hide-inclusion-graph --show-stats bans - --hide-inclusion-graph --show-stats licenses steps: diff --git a/Cargo.lock b/Cargo.lock index 1f62b129..1520018c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -818,7 +818,7 @@ dependencies = [ [[package]] name = "ckb-sdk" version = "3.4.0" -source = "git+https://github.com/eval-exec/ckb-sdk-rust.git?branch=exec/bump-0.118.0#187ab82c9953644d30466b552bbfff4a4c22d37f" +source = "git+https://github.com/eval-exec/ckb-sdk-rust.git?branch=exec/bump-0.118.0#d068582630990de599f17d914d56cd233c5fb3f4" dependencies = [ "anyhow", "bech32 0.8.1", diff --git a/deny.toml b/deny.toml index 1a7fc0c5..f5f097a5 100644 --- a/deny.toml +++ b/deny.toml @@ -90,6 +90,16 @@ ignore = [ # See https://spdx.org/licenses/ for list of possible licenses # [possible values: any SPDX 3.11 short identifier (+ optional exception)]. allow = [ + "Apache-2.0", + "BSD-2-Clause", + "BSD-3-Clause", + "CC0-1.0", + "ISC", + "MIT", + "MITNFA", + "Unicode-DFS-2016", + "BSL-1.0", + "MPL-2.0" #"MIT", #"Apache-2.0", #"Apache-2.0 WITH LLVM-exception", diff --git a/src/interactive.rs b/src/interactive.rs index c99f3442..c91e6164 100644 --- a/src/interactive.rs +++ b/src/interactive.rs @@ -6,6 +6,7 @@ use ansi_term::Colour::Green; use regex::Regex; use rustyline::config::Configurer; use rustyline::error::ReadlineError; +use rustyline::history::FileHistory; use rustyline::{Cmd, CompletionType, Config, EditMode, Editor, KeyEvent}; use serde_json::json; @@ -100,19 +101,20 @@ impl InteractiveEnv { } }; - let rl_mode = |rl: &mut Editor, is_list: bool, is_emacs: bool| { - if is_list { - rl.set_completion_type(CompletionType::List) - } else { - rl.set_completion_type(CompletionType::Circular) - } + let rl_mode = + |rl: &mut Editor, is_list: bool, is_emacs: bool| { + if is_list { + rl.set_completion_type(CompletionType::List) + } else { + rl.set_completion_type(CompletionType::Circular) + } - if is_emacs { - rl.set_edit_mode(EditMode::Emacs) - } else { - rl.set_edit_mode(EditMode::Vi) - } - }; + if is_emacs { + rl.set_edit_mode(EditMode::Emacs) + } else { + rl.set_edit_mode(EditMode::Vi) + } + }; let mut plugin_sub_cmds = Vec::new(); let mut parser = self.parser.clone(); @@ -132,8 +134,9 @@ impl InteractiveEnv { let rl_config = Config::builder() .history_ignore_space(true) .max_history_size(1000) + .map_err(|err| err.to_string())? .build(); - let mut rl = Editor::with_config(rl_config); + let mut rl = Editor::with_config(rl_config).map_err(|err| err.to_string())?; let helper = CkbCompleter::new(parser.clone()); rl.set_helper(Some(helper)); rl.bind_sequence(KeyEvent::alt('n'), Cmd::HistorySearchForward); @@ -160,7 +163,7 @@ impl InteractiveEnv { eprintln!("{}", err); } } - rl.add_history_entry(line.as_str()); + let _ = rl.add_history_entry(line.as_str()); } Err(ReadlineError::Interrupted) => { println!("CTRL-C"); diff --git a/src/utils/completer.rs b/src/utils/completer.rs index c31e2366..7aad2628 100644 --- a/src/utils/completer.rs +++ b/src/utils/completer.rs @@ -12,18 +12,16 @@ use rustyline::{CompletionType, Context}; use rustyline_derive::Helper; #[cfg(unix)] -static DEFAULT_BREAK_CHARS: [u8; 18] = [ - b' ', b'\t', b'\n', b'"', b'\\', b'\'', b'`', b'@', b'$', b'>', b'<', b'=', b';', b'|', b'&', - b'{', b'(', b'\0', +static DEFAULT_BREAK_CHARS: [char; 18] = [ + ' ', '\t', '\n', '"', '\\', '\'', '`', '@', '$', '>', '<', '=', ';', '|', '&', '{', '(', '\0', ]; #[cfg(unix)] static ESCAPE_CHAR: Option = Some('\\'); // Remove \ to make file completion works on windows #[cfg(windows)] -static DEFAULT_BREAK_CHARS: [u8; 17] = [ - b' ', b'\t', b'\n', b'"', b'\'', b'`', b'@', b'$', b'>', b'<', b'=', b';', b'|', b'&', b'{', - b'(', b'\0', +static DEFAULT_BREAK_CHARS: [char; 17] = [ + ' ', '\t', '\n', '"', '\'', '`', '@', '$', '>', '<', '=', ';', '|', '&', '{', '(', '\0', ]; #[cfg(windows)] static ESCAPE_CHAR: Option = None; @@ -127,7 +125,9 @@ impl<'a> Completer for CkbCompleter<'a> { pos: usize, ctx: &Context, ) -> Result<(usize, Vec), ReadlineError> { - let (start, word) = extract_word(line, pos, ESCAPE_CHAR, &DEFAULT_BREAK_CHARS); + let (start, word) = extract_word(line, pos, ESCAPE_CHAR, |char| { + DEFAULT_BREAK_CHARS.contains(&char) + }); let args = shell_words::split(&line[..pos]).unwrap(); let word_lower = word.to_lowercase(); let tmp_pair = Self::find_subcommand( diff --git a/test/src/spec/udt/mod.rs b/test/src/spec/udt/mod.rs index 41a25bc1..6701e4f7 100644 --- a/test/src/spec/udt/mod.rs +++ b/test/src/spec/udt/mod.rs @@ -33,9 +33,9 @@ pub fn prepare(setup: &mut Setup, tmp_path: &str) { let owner_key = format!("{}/owner", tmp_path); let account1_key = format!("{}/account1", tmp_path); let account2_key = format!("{}/account2", tmp_path); - fs::write(&owner_key, OWNER_KEY).unwrap(); - fs::write(&account1_key, ACCOUNT1_KEY).unwrap(); - fs::write(&account2_key, ACCOUNT2_KEY).unwrap(); + fs::write(owner_key, OWNER_KEY).unwrap(); + fs::write(account1_key, ACCOUNT1_KEY).unwrap(); + fs::write(account2_key, ACCOUNT2_KEY).unwrap(); let acp_bin = format!("{}/acp", tmp_path); let cheque_bin = format!("{}/cheque", tmp_path); @@ -158,7 +158,7 @@ pub fn prepare(setup: &mut Setup, tmp_path: &str) { let cell_deps_path = format!("{}/cell_deps.json", tmp_path); fs::write( cell_deps_path, - &serde_json::to_string_pretty(&cell_deps).unwrap(), + serde_json::to_string_pretty(&cell_deps).unwrap(), ) .unwrap();