Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pdl-live-react/src-tauri/src/pdl/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,25 @@ impl<'a> Interpreter<'a> {
async fn run_read(&mut self, block: &ReadBlock, _context: Context) -> Interpretation {
let trace = block.clone();

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

let buffer = match &block.read {
Value::String(file_path) => Ok(read_file_to_string(self.path_to(file_path))?),
Value::Null => {
let mut buffer = String::new();
::std::io::stdin().read_line(&mut buffer)?;
let mut bytes_read = ::std::io::stdin().read_line(&mut buffer)?;
if let Some(true) = block.multiline {
while bytes_read > 0 {
bytes_read = ::std::io::stdin().read_line(&mut buffer)?;
}
}
Ok(buffer)
}
x => Err(Box::<dyn Error + Send + Sync>::from(format!(
Expand Down
5 changes: 2 additions & 3 deletions pdl-live-react/src-tauri/tests/cli/read-stdin.pdl
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
text:
- message: How are you?
read: null
message: How are you?
read: null