@@ -32,10 +32,23 @@ use log::*;
32
32
use notify:: Watcher ;
33
33
use stdext:: unwrap;
34
34
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
+
35
47
fn start_kernel (
36
48
connection_file : ConnectionFile ,
37
49
r_args : Vec < String > ,
38
50
startup_file : Option < String > ,
51
+ _session_mode : SessionMode , // TODO: Pass this to R to set the session mode
39
52
capture_streams : bool ,
40
53
) {
41
54
// Create a new kernel from the connection file
@@ -196,6 +209,7 @@ fn parse_file(
196
209
connection_file : & String ,
197
210
r_args : Vec < String > ,
198
211
startup_file : Option < String > ,
212
+ session_mode : SessionMode ,
199
213
capture_streams : bool ,
200
214
) {
201
215
match ConnectionFile :: from_file ( connection_file) {
@@ -205,7 +219,13 @@ fn parse_file(
205
219
connection_file
206
220
) ;
207
221
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
+ ) ;
209
229
} ,
210
230
Err ( error) => {
211
231
error ! (
@@ -229,6 +249,7 @@ Available options:
229
249
-- arg1 arg2 ... Set the argument list to pass to R; defaults to
230
250
--interactive
231
251
--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)
232
253
--no-capture-streams Do not capture stdout/stderr from R
233
254
--version Print the version of Ark
234
255
--log FILE Log to the given file (if not specified, stdout/stderr
@@ -251,6 +272,7 @@ fn main() {
251
272
252
273
let mut connection_file: Option < String > = None ;
253
274
let mut startup_file: Option < String > = None ;
275
+ let mut session_mode = SessionMode :: Console ;
254
276
let mut log_file: Option < String > = None ;
255
277
let mut startup_notifier_file: Option < String > = None ;
256
278
let mut startup_delay: Option < std:: time:: Duration > = None ;
@@ -281,6 +303,22 @@ fn main() {
281
303
break ;
282
304
}
283
305
} ,
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
+ } ,
284
322
"--version" => {
285
323
println ! ( "Ark {}" , env!( "CARGO_PKG_VERSION" ) ) ;
286
324
has_action = true ;
@@ -437,6 +475,12 @@ fn main() {
437
475
438
476
// Parse the connection file and start the kernel
439
477
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
+ ) ;
441
485
}
442
486
}
0 commit comments