Skip to content

Commit cd5fc43

Browse files
committed
Use R_BANNER in unified write_console()
1 parent a4f5894 commit cd5fc43

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

crates/ark/src/interface.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,31 +1308,33 @@ This is a Positron limitation we plan to fix. In the meantime, you can:
13081308
}
13091309

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

1317+
if !RMain::is_initialized() {
1318+
// During init, consider all output to be part of the startup banner
1319+
unsafe { R_BANNER.push_str(&content) };
1320+
return;
1321+
}
1322+
1323+
let r_main = RMain::get_mut();
1324+
13171325
// To capture the current `debug: <call>` output, for use in the debugger's
13181326
// match based fallback
1319-
self.dap.handle_stdout(&content);
1327+
r_main.dap.handle_stdout(&content);
13201328

13211329
let stream = if otype == 0 {
13221330
Stream::Stdout
13231331
} else {
13241332
Stream::Stderr
13251333
};
13261334

1327-
if !RMain::is_initialized() {
1328-
// During init, consider all output to be part of the startup banner
1329-
self.banner_output.push_str(&content);
1330-
return;
1331-
}
1332-
13331335
// If active execution request is silent don't broadcast
13341336
// any output
1335-
if let Some(ref req) = self.active_request {
1337+
if let Some(ref req) = r_main.active_request {
13361338
if req.request.silent {
13371339
return;
13381340
}
@@ -1348,7 +1350,7 @@ This is a Positron limitation we plan to fix. In the meantime, you can:
13481350
// differentiate, but that could change in the future:
13491351
// https://github.com/posit-dev/positron/issues/1881
13501352
if otype == 0 && is_auto_printing() {
1351-
self.autoprint_output.push_str(&content);
1353+
r_main.autoprint_output.push_str(&content);
13521354
return;
13531355
}
13541356

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

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

16821684
#[no_mangle]
16831685
pub extern "C" fn r_write_console(buf: *const c_char, buflen: i32, otype: i32) {
1684-
let main = RMain::get_mut();
1685-
main.write_console(buf, buflen, otype);
1686+
RMain::write_console(buf, buflen, otype);
16861687
}
16871688

16881689
#[no_mangle]

0 commit comments

Comments
 (0)