Skip to content

Commit 6327455

Browse files
committed
feat: add terminal setting & unsetting
1 parent 7e78f22 commit 6327455

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/session.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,20 @@ impl Session {
4848
true
4949
}
5050

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()
51+
/// Unsets the terminal for this session if it is the given terminal.
52+
pub fn unset_terminal(&self, term: &Arc<dyn Any + Send + Sync>) -> bool {
53+
let mut guard = self.terminal.lock();
54+
if guard.as_ref().is_some_and(|it| Arc::ptr_eq(it, term)) {
55+
*guard = None;
56+
true
57+
} else {
58+
false
59+
}
60+
}
61+
62+
/// Gets the terminal for this session, if it exists.
63+
pub fn terminal(&self) -> Option<Arc<dyn Any + Send + Sync>> {
64+
self.terminal.lock().clone()
5465
}
5566
}
5667

0 commit comments

Comments
 (0)