@@ -2,7 +2,7 @@ use alloc::{
22 sync:: { Arc , Weak } ,
33 vec:: Vec ,
44} ;
5- use core:: fmt;
5+ use core:: { any :: Any , fmt} ;
66
77use kspin:: SpinNoIrq ;
88use weak_map:: WeakMap ;
@@ -13,7 +13,7 @@ use crate::{Pid, ProcessGroup};
1313pub struct Session {
1414 sid : Pid ,
1515 pub ( crate ) process_groups : SpinNoIrq < WeakMap < Pid , Weak < ProcessGroup > > > ,
16- // TODO: shell job control
16+ terminal : SpinNoIrq < Option < Arc < dyn Any + Send + Sync > > > ,
1717}
1818
1919impl Session {
@@ -22,6 +22,7 @@ impl Session {
2222 Arc :: new ( Self {
2323 sid,
2424 process_groups : SpinNoIrq :: new ( WeakMap :: new ( ) ) ,
25+ terminal : SpinNoIrq :: new ( None ) ,
2526 } )
2627 }
2728}
@@ -36,6 +37,21 @@ impl Session {
3637 pub fn process_groups ( & self ) -> Vec < Arc < ProcessGroup > > {
3738 self . process_groups . lock ( ) . values ( ) . collect ( )
3839 }
40+
41+ /// Sets the terminal for this session.
42+ pub fn set_terminal_with ( & self , terminal : impl FnOnce ( ) -> Arc < dyn Any + Send + Sync > ) -> bool {
43+ let mut guard = self . terminal . lock ( ) ;
44+ if guard. is_some ( ) {
45+ return false ;
46+ }
47+ * guard = Some ( terminal ( ) ) ;
48+ true
49+ }
50+
51+ /// Unsets the terminal for this session, returning the previous terminal if it existed.
52+ pub fn unset_terminal ( & self ) -> Option < Arc < dyn Any + Send + Sync > > {
53+ self . terminal . lock ( ) . take ( )
54+ }
3955}
4056
4157impl fmt:: Debug for Session {
0 commit comments