@@ -51,6 +51,7 @@ pub struct EngineCtx {
5151 pub ( crate ) input_stack : Vec < InputState > ,
5252 pub ( crate ) input_ptr : usize ,
5353 pub ( crate ) cur_input : InputState ,
54+ pub ( crate ) interaction : InteractionMode ,
5455
5556 pub ( crate ) eqtb : Vec < MemoryWord > ,
5657 pub ( crate ) prim : Box < [ B32x2 ; PRIM_SIZE + 1 ] > ,
@@ -59,6 +60,28 @@ pub struct EngineCtx {
5960 pub ( crate ) buffer : Vec < char > ,
6061}
6162
63+ #[ derive( Copy , Clone , PartialEq , Eq ) ]
64+ pub enum InteractionMode {
65+ Batch = 0 ,
66+ Nonstop ,
67+ Scroll ,
68+ ErrorStop ,
69+ }
70+
71+ impl TryFrom < u8 > for InteractionMode {
72+ type Error = u8 ;
73+
74+ fn try_from ( value : u8 ) -> Result < Self , Self :: Error > {
75+ Ok ( match value {
76+ 0 => InteractionMode :: Batch ,
77+ 1 => InteractionMode :: Nonstop ,
78+ 2 => InteractionMode :: Scroll ,
79+ 3 => InteractionMode :: ErrorStop ,
80+ _ => return Err ( value) ,
81+ } )
82+ }
83+ }
84+
6285#[ derive( Clone , Default , PartialEq ) ]
6386#[ repr( C ) ]
6487pub struct InputState {
@@ -108,6 +131,7 @@ impl EngineCtx {
108131 input_stack : Vec :: new ( ) ,
109132 input_ptr : 0 ,
110133 cur_input : InputState :: default ( ) ,
134+ interaction : InteractionMode :: Batch ,
111135
112136 eqtb : Vec :: new ( ) ,
113137 prim : Box :: new ( [ B32x2 { s0 : 0 , s1 : 0 } ; PRIM_SIZE + 1 ] ) ,
@@ -501,6 +525,17 @@ pub extern "C" fn set_cur_input(val: InputState) {
501525 ENGINE_CTX . with_borrow_mut ( |engine| engine. cur_input = val)
502526}
503527
528+ #[ no_mangle]
529+ pub extern "C" fn interaction ( ) -> u8 {
530+ ENGINE_CTX . with_borrow ( |engine| engine. interaction as u8 )
531+ }
532+
533+ #[ no_mangle]
534+ pub extern "C" fn set_interaction ( val : u8 ) {
535+ ENGINE_CTX
536+ . with_borrow_mut ( |engine| engine. interaction = InteractionMode :: try_from ( val) . unwrap ( ) )
537+ }
538+
504539#[ no_mangle]
505540pub extern "C" fn eqtb ( idx : usize ) -> MemoryWord {
506541 ENGINE_CTX . with_borrow ( |engine| engine. eqtb [ idx] )
0 commit comments