-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
nframe()
to detect prompts like readline()
- Loading branch information
Showing
3 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// session.rs | ||
// | ||
// Copyright (C) 2023 Posit Software, PBC. All rights reserved. | ||
// | ||
// | ||
|
||
use std::sync::Once; | ||
|
||
use libR_sys::*; | ||
|
||
use crate::utils::r_try_eval_silent; | ||
use crate::vector::integer_vector::IntegerVector; | ||
use crate::vector::Vector; | ||
|
||
pub fn r_n_frame() -> crate::error::Result<i32> { | ||
SESSION_INIT.call_once(init_interface); | ||
|
||
unsafe { | ||
let ffi = r_try_eval_silent(NFRAME_CALL as SEXP, R_BaseEnv)?; | ||
let n_frame = IntegerVector::new(ffi)?; | ||
Ok(n_frame.get_unchecked_elt(0)) | ||
} | ||
} | ||
|
||
// Globals | ||
static SESSION_INIT: Once = Once::new(); | ||
static mut NFRAME_CALL: usize = 0; | ||
|
||
fn init_interface() { | ||
unsafe { | ||
let nframe_call = crate::r_lang!(crate::r_symbol!("sys.nframe")); | ||
R_PreserveObject(nframe_call); | ||
NFRAME_CALL = nframe_call as usize; | ||
} | ||
} |