diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-21 20:19:54 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-21 20:22:57 +0300 |
| commit | 866aaf740e10fcfce169aaf81380ea0257fbe272 (patch) | |
| tree | f815392b7c6b24a7c0de14e655bd635656383813 /src/terminal/runtime_registry.rs | |
| parent | ca579c402d5668560ca13059f82c03178be18b2a (diff) | |
refactor: separate server client boundaries
Diffstat (limited to 'src/terminal/runtime_registry.rs')
| -rw-r--r-- | src/terminal/runtime_registry.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/terminal/runtime_registry.rs b/src/terminal/runtime_registry.rs new file mode 100644 index 00000000..d1aeeae2 --- /dev/null +++ b/src/terminal/runtime_registry.rs @@ -0,0 +1,54 @@ +use std::collections::HashMap; + +use super::{TerminalId, TerminalRuntime}; + +/// Server-owned live terminal runtimes, keyed by durable terminal id. +/// +/// This sits outside `AppState` so pure state can stay focused on workspace, +/// pane, and terminal metadata while the server/application layer owns PTYs, +/// parser backends, detector tasks, and channels. +#[derive(Default)] +pub(crate) struct TerminalRuntimeRegistry { + runtimes: HashMap<TerminalId, TerminalRuntime>, +} + +impl TerminalRuntimeRegistry { + pub(crate) fn new() -> Self { + Self::default() + } + + pub(crate) fn get(&self, terminal_id: &TerminalId) -> Option<&TerminalRuntime> { + self.runtimes.get(terminal_id) + } + + pub(crate) fn insert( + &mut self, + terminal_id: TerminalId, + runtime: TerminalRuntime, + ) -> Option<TerminalRuntime> { + self.runtimes.insert(terminal_id, runtime) + } + + pub(crate) fn remove(&mut self, terminal_id: &TerminalId) -> Option<TerminalRuntime> { + self.runtimes.remove(terminal_id) + } + + pub(crate) fn values(&self) -> impl Iterator<Item = &TerminalRuntime> { + self.runtimes.values() + } + + pub(crate) fn len(&self) -> usize { + self.runtimes.len() + } + + #[cfg(test)] + pub(crate) fn drain(&mut self) -> impl Iterator<Item = (TerminalId, TerminalRuntime)> + '_ { + self.runtimes.drain() + } +} + +impl From<HashMap<TerminalId, TerminalRuntime>> for TerminalRuntimeRegistry { + fn from(runtimes: HashMap<TerminalId, TerminalRuntime>) -> Self { + Self { runtimes } + } +} |
