1use gpui::{Entity, ModelHandle};
2use smol::channel;
3use std::marker::PhantomData;
4
5pub fn sample_text(rows: usize, cols: usize) -> String {
6 let mut text = String::new();
7 for row in 0..rows {
8 let c: char = ('a' as u32 + row as u32) as u8 as char;
9 let mut line = c.to_string().repeat(cols);
10 if row < rows - 1 {
11 line.push('\n');
12 }
13 text += &line;
14 }
15 text
16}
17
18pub struct Observer<T>(PhantomData<T>);
19
20impl<T: 'static> Entity for Observer<T> {
21 type Event = ();
22}
23
24impl<T: Entity> Observer<T> {
25 pub fn new(
26 handle: &ModelHandle<T>,
27 cx: &mut gpui::TestAppContext,
28 ) -> (ModelHandle<Self>, channel::Receiver<()>) {
29 let (notify_tx, notify_rx) = channel::unbounded();
30 let observer = cx.add_model(|cx| {
31 cx.observe(handle, move |_, _, _| {
32 let _ = notify_tx.try_send(());
33 })
34 .detach();
35 Observer(PhantomData)
36 });
37 (observer, notify_rx)
38 }
39}