Skip to content

Commit

Permalink
Use R_BANNER in unified write_console()
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Oct 4, 2024
1 parent a4f5894 commit cd5fc43
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions crates/ark/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,31 +1308,33 @@ This is a Positron limitation we plan to fix. In the meantime, you can:
}

/// Invoked by R to write output to the console.
fn write_console(&mut self, buf: *const c_char, _buflen: i32, otype: i32) {
fn write_console(buf: *const c_char, _buflen: i32, otype: i32) {
let content = match console_to_utf8(buf) {
Ok(content) => content,
Err(err) => panic!("Failed to read from R buffer: {err:?}"),
};

if !RMain::is_initialized() {
// During init, consider all output to be part of the startup banner
unsafe { R_BANNER.push_str(&content) };
return;
}

let r_main = RMain::get_mut();

// To capture the current `debug: <call>` output, for use in the debugger's
// match based fallback
self.dap.handle_stdout(&content);
r_main.dap.handle_stdout(&content);

let stream = if otype == 0 {
Stream::Stdout
} else {
Stream::Stderr
};

if !RMain::is_initialized() {
// During init, consider all output to be part of the startup banner
self.banner_output.push_str(&content);
return;
}

// If active execution request is silent don't broadcast
// any output
if let Some(ref req) = self.active_request {
if let Some(ref req) = r_main.active_request {
if req.request.silent {
return;
}
Expand All @@ -1348,7 +1350,7 @@ This is a Positron limitation we plan to fix. In the meantime, you can:
// differentiate, but that could change in the future:
// https://github.com/posit-dev/positron/issues/1881
if otype == 0 && is_auto_printing() {
self.autoprint_output.push_str(&content);
r_main.autoprint_output.push_str(&content);
return;
}

Expand All @@ -1357,7 +1359,7 @@ This is a Positron limitation we plan to fix. In the meantime, you can:
name: stream,
text: content,
});
self.iopub_tx.send(message).unwrap();
r_main.iopub_tx.send(message).unwrap();
}

/// Invoked by R to change busy state
Expand Down Expand Up @@ -1681,8 +1683,7 @@ fn new_cstring(x: String) -> CString {

#[no_mangle]
pub extern "C" fn r_write_console(buf: *const c_char, buflen: i32, otype: i32) {
let main = RMain::get_mut();
main.write_console(buf, buflen, otype);
RMain::write_console(buf, buflen, otype);
}

#[no_mangle]
Expand Down

0 comments on commit cd5fc43

Please sign in to comment.