Skip to content

Commit c68204c

Browse files
DavisVaughanlionel-
authored andcommitted
WIP handling for pending line in read_console()
1 parent 92a02bd commit c68204c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

crates/ark/src/interface.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ impl RMain {
454454
tasks_idle_rx,
455455
pending_futures: HashMap::new(),
456456
session_mode,
457+
pending_lines: Vec::new(),
457458
}
458459
}
459460

@@ -596,6 +597,10 @@ impl RMain {
596597
buflen: c_int,
597598
_hist: c_int,
598599
) -> ConsoleResult {
600+
if let Some(console_result) = self.handle_pending_line(buf, buflen) {
601+
return console_result;
602+
}
603+
599604
let info = Self::prompt_info(prompt);
600605
log::trace!("R prompt: {}", info.input_prompt);
601606

@@ -1032,6 +1037,24 @@ impl RMain {
10321037
}
10331038
}
10341039

1040+
fn handle_pending_line(&mut self, buf: *mut c_uchar, buflen: c_int) -> Option<ConsoleResult> {
1041+
if self.error_occurred {
1042+
// If an error has occurred, we've already sent a complete expression that resulted in
1043+
// an error. Flush the remaining lines and return to `read_console()`, who will handle
1044+
// that error.
1045+
self.pending_lines.clear();
1046+
return None;
1047+
}
1048+
1049+
let Some(input) = self.pending_lines.pop() else {
1050+
// No pending lines
1051+
return None;
1052+
};
1053+
1054+
Self::on_console_input(buf, buflen, input);
1055+
Some(ConsoleResult::NewInput)
1056+
}
1057+
10351058
fn handle_input(&mut self, input: String) -> String {
10361059
// TODO: Going back and forth from Vec<String> to iterator is not nice
10371060
let mut lines: Vec<String> = lines(&input).into_iter().rev().map(String::from).collect();
@@ -1071,6 +1094,8 @@ impl RMain {
10711094
let buflen = buflen - 2;
10721095

10731096
if input.len() > buflen {
1097+
// TODO!: Probably want to clear the `pending_lines` if we get here
1098+
// TODO!: Also think about what happens if R gets left in an incomplete state (invokeRestart("abort")?)
10741099
log::error!("Console input too large for buffer, writing R error.");
10751100
input = Self::buffer_overflow_call();
10761101
}

0 commit comments

Comments
 (0)