Skip to content

Commit e1c7b33

Browse files
authored
Merge pull request #264 from posit-dev/feature/runtime-sessions
Add stubs for session mode argument
2 parents 1fb1018 + 1d6e828 commit e1c7b33

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

crates/ark/src/main.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,23 @@ use log::*;
3232
use notify::Watcher;
3333
use stdext::unwrap;
3434

35+
/// An enum representing the different modes in which the R session can run.
36+
enum SessionMode {
37+
/// A session with an interactive console (REPL), such as in Positron.
38+
Console,
39+
40+
/// A session in a Jupyter or Jupyter-like notebook.
41+
Notebook,
42+
43+
/// A background session, typically not connected to any UI.
44+
Background,
45+
}
46+
3547
fn start_kernel(
3648
connection_file: ConnectionFile,
3749
r_args: Vec<String>,
3850
startup_file: Option<String>,
51+
_session_mode: SessionMode, // TODO: Pass this to R to set the session mode
3952
capture_streams: bool,
4053
) {
4154
// Create a new kernel from the connection file
@@ -196,6 +209,7 @@ fn parse_file(
196209
connection_file: &String,
197210
r_args: Vec<String>,
198211
startup_file: Option<String>,
212+
session_mode: SessionMode,
199213
capture_streams: bool,
200214
) {
201215
match ConnectionFile::from_file(connection_file) {
@@ -205,7 +219,13 @@ fn parse_file(
205219
connection_file
206220
);
207221
debug!("Connection data: {:?}", connection);
208-
start_kernel(connection, r_args, startup_file, capture_streams);
222+
start_kernel(
223+
connection,
224+
r_args,
225+
startup_file,
226+
session_mode,
227+
capture_streams,
228+
);
209229
},
210230
Err(error) => {
211231
error!(
@@ -229,6 +249,7 @@ Available options:
229249
-- arg1 arg2 ... Set the argument list to pass to R; defaults to
230250
--interactive
231251
--startup-file FILE An R file to run on session startup
252+
--session-mode MODE The mode in which the session is running (console, notebook, background)
232253
--no-capture-streams Do not capture stdout/stderr from R
233254
--version Print the version of Ark
234255
--log FILE Log to the given file (if not specified, stdout/stderr
@@ -251,6 +272,7 @@ fn main() {
251272

252273
let mut connection_file: Option<String> = None;
253274
let mut startup_file: Option<String> = None;
275+
let mut session_mode = SessionMode::Console;
254276
let mut log_file: Option<String> = None;
255277
let mut startup_notifier_file: Option<String> = None;
256278
let mut startup_delay: Option<std::time::Duration> = None;
@@ -281,6 +303,22 @@ fn main() {
281303
break;
282304
}
283305
},
306+
"--session-mode" => {
307+
if let Some(mode) = argv.next() {
308+
session_mode = match mode.as_str() {
309+
"console" => SessionMode::Console,
310+
"notebook" => SessionMode::Notebook,
311+
"background" => SessionMode::Background,
312+
_ => {
313+
eprintln!("Invalid session mode: '{}' (expected console, notebook, or background)", mode);
314+
break;
315+
},
316+
};
317+
} else {
318+
eprintln!("A session mode must be specified with the --session-mode argument.");
319+
break;
320+
}
321+
},
284322
"--version" => {
285323
println!("Ark {}", env!("CARGO_PKG_VERSION"));
286324
has_action = true;
@@ -437,6 +475,12 @@ fn main() {
437475

438476
// Parse the connection file and start the kernel
439477
if let Some(connection) = connection_file {
440-
parse_file(&connection, r_args, startup_file, capture_streams);
478+
parse_file(
479+
&connection,
480+
r_args,
481+
startup_file,
482+
session_mode,
483+
capture_streams,
484+
);
441485
}
442486
}

0 commit comments

Comments
 (0)