agentmux_srv/backend/blockcontroller/
term_size.rs1use std::collections::HashMap;
10use std::sync::{LazyLock, Mutex};
11
12static SIZES: LazyLock<Mutex<HashMap<String, (u16, u16)>>> = LazyLock::new(|| Mutex::new(HashMap::new()));
13
14pub fn record(block_id: &str, rows: u16, cols: u16) {
16 SIZES.lock().unwrap_or_else(|p| p.into_inner()).insert(block_id.to_string(), (rows, cols));
17}
18
19pub fn get(block_id: &str) -> Option<(u16, u16)> {
21 SIZES.lock().unwrap_or_else(|p| p.into_inner()).get(block_id).copied()
22}
23
24pub fn forget(block_id: &str) {
26 SIZES.lock().unwrap_or_else(|p| p.into_inner()).remove(block_id);
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn the_last_size_wins_until_forgotten() {
35 let block = uuid::Uuid::new_v4().to_string();
36 assert_eq!(get(&block), None);
37 record(&block, 25, 200);
38 record(&block, 40, 120);
39 assert_eq!(get(&block), Some((40, 120)));
40 forget(&block);
41 assert_eq!(get(&block), None);
42 }
43}