Skip to content

Commit 29a69b8

Browse files
committed
update rustyline
1 parent 3087d48 commit 29a69b8

File tree

5 files changed

+115
-31
lines changed

5 files changed

+115
-31
lines changed

Cargo.lock

Lines changed: 64 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ flame = { version = "0.2", optional = true }
4141
flamescope = { version = "0.1", optional = true }
4242

4343
[target.'cfg(not(target_os = "wasi"))'.dependencies]
44-
rustyline = "6.0"
44+
rustyline = "8.0"
4545

4646
[dev-dependencies]
4747
cpython = "0.5.0"

src/shell/helper.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ cfg_if::cfg_if! {
163163
.unwrap_or_else(|| (line.len(), vec!["\t".to_owned()])))
164164
}
165165
}
166-
167-
impl Hinter for ShellHelper<'_> {}
166+
impl Hinter for ShellHelper<'_> {
167+
type Hint = String;
168+
}
168169
impl Highlighter for ShellHelper<'_> {}
169170
impl Validator for ShellHelper<'_> {}
170171
impl Helper for ShellHelper<'_> {}

vm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ uname = "0.1.1"
122122
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
123123
gethostname = "0.2.0"
124124
socket2 = "0.3.19"
125-
rustyline = "6.0"
125+
rustyline = "8.0"
126126
openssl = { version = "0.10.32", features = ["vendored"], optional = true }
127127
openssl-sys = { version = "0.9", optional = true }
128128
openssl-probe = { version = "0.1", optional = true }

vm/src/readline.rs

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,21 @@ mod rustyline_readline {
6868
pub trait Helper: rustyline::Helper {}
6969
impl<T: rustyline::Helper> Helper for T {}
7070

71+
/// Readline: the REPL
7172
pub struct Readline<H: Helper> {
7273
repl: rustyline::Editor<H>,
7374
}
7475

7576
impl<H: Helper> Readline<H> {
7677
pub fn new(helper: H) -> Self {
77-
use rustyline::{At, Cmd, CompletionType, Config, Editor, KeyPress, Movement, Word};
78+
use rustyline::*;
7879
let mut repl = Editor::with_config(
7980
Config::builder()
8081
.completion_type(CompletionType::List)
8182
.tab_stop(8)
83+
.bracketed_paste(false) // multi-line paste
8284
.build(),
8385
);
84-
// Parse multiple lines correctly
85-
repl.bind_sequence(KeyPress::BracketedPasteStart, Cmd::Noop);
86-
87-
repl.bind_sequence(
88-
KeyPress::ControlLeft,
89-
Cmd::Move(Movement::BackwardWord(1, Word::Vi)),
90-
);
91-
repl.bind_sequence(
92-
KeyPress::ControlRight,
93-
Cmd::Move(Movement::ForwardWord(1, At::AfterEnd, Word::Vi)),
94-
);
9586
repl.set_helper(Some(helper));
9687
Readline { repl }
9788
}
@@ -131,6 +122,48 @@ mod rustyline_readline {
131122
}
132123
}
133124
}
125+
126+
#[cfg(test)]
127+
mod test_rusty_readline {
128+
use super::*;
129+
use rustyline::{completion::Completer, highlight::Highlighter,
130+
validate::Validator, Context, hint::Hinter};
131+
use rustyline::error::ReadlineError;
132+
use crate::readline::ReadlineResult::Line;
133+
134+
struct HelperShim {
135+
136+
}
137+
impl rustyline::Helper for HelperShim {}
138+
impl Highlighter for HelperShim {}
139+
impl Validator for HelperShim {}
140+
impl Completer for HelperShim {
141+
type Candidate = String;
142+
143+
fn complete(
144+
&self,
145+
line: &str,
146+
pos: usize,
147+
_ctx: &Context,
148+
) -> rustyline::Result<(usize, Vec<String>)> {
149+
Err(ReadlineError::Interrupted)
150+
}
151+
}
152+
impl Hinter for HelperShim {
153+
type Hint = String;
154+
}
155+
// impl Helper for ShellHelper<'_> {}
156+
#[test]
157+
fn test_multi_read_line() {
158+
159+
let mut repl = Readline::new(HelperShim { });
160+
if let Line(line) = repl.readline("print('hello')\nprint('hello2')\n") {
161+
assert_eq!(line, "print('hello')");
162+
}
163+
164+
}
165+
166+
}
134167
}
135168

136169
#[cfg(target_arch = "wasm32")]
@@ -159,3 +192,4 @@ impl<H: Helper> Readline<H> {
159192
self.0.readline(prompt)
160193
}
161194
}
195+

0 commit comments

Comments
 (0)