Skip to content

Commit 3910c3d

Browse files
committed
feat: add support for multiline reads to rust interpreter
Signed-off-by: Nick Mitchell <[email protected]>
1 parent bf70518 commit 3910c3d

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

pdl-live-react/src-tauri/src/pdl/interpreter.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,25 @@ impl<'a> Interpreter<'a> {
276276
async fn run_read(&mut self, block: &ReadBlock, _context: Context) -> Interpretation {
277277
let trace = block.clone();
278278

279-
if let Some(message) = &block.message {
280-
println!("{}", message);
281-
}
279+
println!(
280+
"{}",
281+
match (&block.message, block.multiline) {
282+
(Some(message), _) => message.as_str(),
283+
(None, Some(true)) => "Enter/Paste your content. Ctrl-D to save it.",
284+
_ => "How can i help you?",
285+
}
286+
);
282287

283288
let buffer = match &block.read {
284289
Value::String(file_path) => Ok(read_file_to_string(self.path_to(file_path))?),
285290
Value::Null => {
286291
let mut buffer = String::new();
287-
::std::io::stdin().read_line(&mut buffer)?;
292+
let mut bytes_read = ::std::io::stdin().read_line(&mut buffer)?;
293+
if let Some(true) = block.multiline {
294+
while bytes_read > 0 {
295+
bytes_read = ::std::io::stdin().read_line(&mut buffer)?;
296+
}
297+
}
288298
Ok(buffer)
289299
}
290300
x => Err(Box::<dyn Error + Send + Sync>::from(format!(
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
text:
2-
- message: How are you?
3-
read: null
1+
message: How are you?
2+
read: null

0 commit comments

Comments
 (0)