Skip to content

Commit

Permalink
Update rustyline
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <execvy@gmail.com>
  • Loading branch information
eval-exec committed Sep 19, 2024
1 parent ed8cb2a commit f125662
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 17 additions & 14 deletions src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -100,19 +101,20 @@ impl InteractiveEnv {
}
};

let rl_mode = |rl: &mut Editor<CkbCompleter>, 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<CkbCompleter, FileHistory>, 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();
Expand All @@ -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);
Expand All @@ -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");
Expand Down
14 changes: 7 additions & 7 deletions src/utils/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> = 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<char> = None;
Expand Down Expand Up @@ -127,7 +125,9 @@ impl<'a> Completer for CkbCompleter<'a> {
pos: usize,
ctx: &Context,
) -> Result<(usize, Vec<Pair>), 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(
Expand Down
8 changes: 4 additions & 4 deletions test/src/spec/udt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit f125662

Please sign in to comment.