Skip to content

Commit dafa4fd

Browse files
REPL change: add support for multiline input (#890)
1 parent d499781 commit dafa4fd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ This version is not yet released. If you are reading this on the website, then t
6262
- Add `gh:` prefix for import strings to shorten GitHub imports
6363
- Upgrade to Rust 2024 edition
6464
- Increase minumum Rust version to 1.85.0
65+
- Add support for multiline input in REPL by ending lines with a `\`
6566
### Website
6667
- Reword all documentation and tutorials to no longer refer to a stack
6768
- Introduce argument manipulation modifiers earlier in the tutorial

src/main.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,16 @@ fn repl(mut env: Uiua, mut compiler: Compiler, color: bool, persist: bool, confi
11881188
Err(ReadlineError::Eof | ReadlineError::Interrupted) => break,
11891189
Err(_) => panic!("Failed to read from Stdin"),
11901190
};
1191+
while code.ends_with(r"\") {
1192+
code.pop();
1193+
code.push('\n');
1194+
1195+
code.push_str(&match line_reader.readline("... ") {
1196+
Ok(code) => code,
1197+
Err(ReadlineError::Eof | ReadlineError::Interrupted) => break,
1198+
Err(_) => panic!("Failed to read from Stdin"),
1199+
});
1200+
}
11911201
if code.is_empty() {
11921202
continue;
11931203
}
@@ -1207,7 +1217,13 @@ fn repl(mut env: Uiua, mut compiler: Compiler, color: bool, persist: bool, confi
12071217
let backup_comp = compiler.clone();
12081218
let backup_stack = env.stack().to_vec();
12091219
let res = compiler.load_str(&code).map(drop);
1210-
println!(" {}", color_code(&code, &compiler));
1220+
println!(
1221+
" {}",
1222+
color_code(&code, &compiler)
1223+
.split("\n")
1224+
.collect::<Vec<_>>()
1225+
.join("\n ")
1226+
);
12111227
let res = res.and_then(|()| env.run_compiler(&mut compiler));
12121228

12131229
match res {

0 commit comments

Comments
 (0)