use gpui::{Entity, ModelHandle}; use smol::channel; use std::marker::PhantomData; #[cfg(test)] #[ctor::ctor] fn init_logger() { // std::env::set_var("RUST_LOG", "info"); env_logger::init(); } pub fn sample_text(rows: usize, cols: usize) -> String { let mut text = String::new(); for row in 0..rows { let c: char = ('a' as u32 + row as u32) as u8 as char; let mut line = c.to_string().repeat(cols); if row < rows - 1 { line.push('\n'); } text += &line; } text } pub struct Observer(PhantomData); impl Entity for Observer { type Event = (); } impl Observer { pub fn new( handle: &ModelHandle, cx: &mut gpui::TestAppContext, ) -> (ModelHandle, channel::Receiver<()>) { let (notify_tx, notify_rx) = channel::unbounded(); let observer = cx.add_model(|cx| { cx.observe(handle, move |_, _, _| { let _ = notify_tx.try_send(()); }) .detach(); Observer(PhantomData) }); (observer, notify_rx) } }