Merged main and branch
This commit is contained in:
commit
937cd582e8
6 changed files with 31 additions and 126 deletions
|
@ -1,64 +1,19 @@
|
|||
use std::{path::Path, time::Duration};
|
||||
|
||||
use gpui::{AppContext, ModelHandle, ReadModelWith, TestAppContext, ViewHandle};
|
||||
use gpui::{ModelHandle, TestAppContext, ViewHandle};
|
||||
|
||||
use itertools::Itertools;
|
||||
use project::{Entry, Project, ProjectPath, Worktree};
|
||||
use workspace::{AppState, Workspace};
|
||||
|
||||
use crate::{Terminal, TerminalBuilder, TerminalSize};
|
||||
|
||||
pub struct TerminalTestContext<'a> {
|
||||
pub cx: &'a mut TestAppContext,
|
||||
pub connection: Option<ModelHandle<Terminal>>,
|
||||
}
|
||||
|
||||
impl<'a> TerminalTestContext<'a> {
|
||||
pub fn new(cx: &'a mut TestAppContext, term: bool) -> Self {
|
||||
pub fn new(cx: &'a mut TestAppContext) -> Self {
|
||||
cx.set_condition_duration(Some(Duration::from_secs(5)));
|
||||
|
||||
let size_info = TerminalSize::default();
|
||||
|
||||
let connection = term.then(|| {
|
||||
cx.add_model(|cx| {
|
||||
TerminalBuilder::new(None, None, None, size_info)
|
||||
.unwrap()
|
||||
.subscribe(cx)
|
||||
})
|
||||
});
|
||||
|
||||
TerminalTestContext { cx, connection }
|
||||
}
|
||||
|
||||
pub async fn execute_and_wait<F>(&mut self, command: &str, f: F) -> String
|
||||
where
|
||||
F: Fn(String, &AppContext) -> bool,
|
||||
{
|
||||
let connection = self.connection.take().unwrap();
|
||||
|
||||
let command = command.to_string();
|
||||
connection.update(self.cx, |connection, _| {
|
||||
connection.write_to_pty(command);
|
||||
connection.write_to_pty("\r".to_string());
|
||||
});
|
||||
|
||||
connection
|
||||
.condition(self.cx, |term, cx| {
|
||||
let content = Self::grid_as_str(term);
|
||||
|
||||
f(content, cx)
|
||||
})
|
||||
.await;
|
||||
|
||||
let res = self
|
||||
.cx
|
||||
.read_model_with(&connection, &mut |conn, _: &AppContext| {
|
||||
Self::grid_as_str(conn)
|
||||
});
|
||||
|
||||
self.connection = Some(connection);
|
||||
|
||||
res
|
||||
TerminalTestContext { cx }
|
||||
}
|
||||
|
||||
///Creates a worktree with 1 file: /root.txt
|
||||
|
@ -131,17 +86,6 @@ impl<'a> TerminalTestContext<'a> {
|
|||
project.update(cx, |project, cx| project.set_active_path(Some(p), cx));
|
||||
});
|
||||
}
|
||||
|
||||
fn grid_as_str(connection: &Terminal) -> String {
|
||||
let content = connection.grid();
|
||||
|
||||
let lines = content.display_iter().group_by(|i| i.point.line.0);
|
||||
lines
|
||||
.into_iter()
|
||||
.map(|(_, line)| line.map(|i| i.c).collect::<String>())
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for TerminalTestContext<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue