From 866aaf740e10fcfce169aaf81380ea0257fbe272 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Thu, 21 May 2026 20:19:54 +0300 Subject: refactor: separate server client boundaries --- src/terminal/runtime_registry.rs | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/terminal/runtime_registry.rs (limited to 'src/terminal/runtime_registry.rs') 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, +} + +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 { + self.runtimes.insert(terminal_id, runtime) + } + + pub(crate) fn remove(&mut self, terminal_id: &TerminalId) -> Option { + self.runtimes.remove(terminal_id) + } + + pub(crate) fn values(&self) -> impl Iterator { + self.runtimes.values() + } + + pub(crate) fn len(&self) -> usize { + self.runtimes.len() + } + + #[cfg(test)] + pub(crate) fn drain(&mut self) -> impl Iterator + '_ { + self.runtimes.drain() + } +} + +impl From> for TerminalRuntimeRegistry { + fn from(runtimes: HashMap) -> Self { + Self { runtimes } + } +} -- cgit v1.2.3