diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 545570da89..9b4a163af4 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1194,7 +1194,7 @@ impl Project { !self.is_local() } - pub fn create_terminal_connection( + pub fn create_terminal( &mut self, working_directory: Option, window_id: usize, diff --git a/crates/terminal_view/src/terminal_container_view.rs b/crates/terminal_view/src/terminal_container_view.rs index 322bf5ab52..4a0d47794a 100644 --- a/crates/terminal_view/src/terminal_container_view.rs +++ b/crates/terminal_view/src/terminal_container_view.rs @@ -82,21 +82,22 @@ impl TerminalContainer { let working_directory = get_working_directory(workspace, cx, strategy); let window_id = cx.window_id(); + let project = workspace.project().clone(); let terminal = workspace.project().update(cx, |project, cx| { - project.create_terminal_connection(working_directory, window_id, cx) + project.create_terminal(working_directory, window_id, cx) }); let view = cx.add_view(|cx| TerminalContainer::new(terminal, workspace.database_id(), cx)); workspace.add_item(Box::new(view), cx); } - ///Create a new Terminal view. This spawns a task, a thread, and opens the TTY devices + ///Create a new Terminal view. pub fn new( - model: anyhow::Result>, + maybe_terminal: anyhow::Result>, workspace_id: WorkspaceId, cx: &mut ViewContext, ) -> Self { - let content = match model { + let content = match maybe_terminal { Ok(terminal) => { let item_id = cx.view_id(); let view = cx.add_view(|cx| { @@ -251,8 +252,7 @@ impl Item for TerminalContainer { //Directory of the terminal from outside the shell. There might be //solutions to this, but they are non-trivial and require more IPC Some(TerminalContainer::new( - self.associated_directory.clone(), - false, + Err(anyhow::anyhow!("failed to instantiate terminal")), workspace_id, cx, )) @@ -354,12 +354,13 @@ impl Item for TerminalContainer { } fn deserialize( - _project: ModelHandle, + project: ModelHandle, _workspace: WeakViewHandle, workspace_id: workspace::WorkspaceId, item_id: workspace::ItemId, cx: &mut ViewContext, ) -> Task>> { + let window_id = cx.window_id(); cx.spawn(|pane, mut cx| async move { let cwd = TERMINAL_DB .take_working_directory(item_id, workspace_id) @@ -368,8 +369,12 @@ impl Item for TerminalContainer { .flatten(); cx.update(|cx| { + let terminal = project.update(cx, |project, cx| { + project.create_terminal(cwd, window_id, cx) + }); + Ok(cx.add_view(pane, |cx| { - TerminalContainer::new(cwd, false, workspace_id, cx) + TerminalContainer::new(terminal, workspace_id, cx) })) }) }) diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 506dd1423d..08ed3ecc2d 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -32,7 +32,7 @@ use util::ResultExt; use std::{fmt::Debug, ops::RangeInclusive}; use std::{mem, ops::Range}; -use crate::terminal_view::{DeployContextMenu, TerminalView}; +use crate::{DeployContextMenu, TerminalView}; ///The information generated during layout that is nescessary for painting pub struct LayoutState { diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index dbe861b781..c2747e3ef2 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -22,12 +22,12 @@ use terminal::{ index::Point, term::{search::RegexSearch, TermMode}, }, - Terminal, + Event, Terminal, }; use util::ResultExt; use workspace::{pane, ItemId, WorkspaceId}; -use crate::{persistence::TERMINAL_DB, terminal_element::TerminalElement, Event}; +use crate::{persistence::TERMINAL_DB, terminal_element::TerminalElement}; const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500); diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 1b41613937..2396af6465 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -32,7 +32,7 @@ use settings::{ use smol::process::Command; use std::fs::OpenOptions; use std::{env, ffi::OsStr, panic, path::PathBuf, sync::Arc, thread, time::Duration}; -use terminal_view::{get_working_directory, TerminalContainer}; +use terminal_view::terminal_container_view::{get_working_directory, TerminalContainer}; use fs::RealFs; use settings::watched_json::{watch_keymap_file, watch_settings_file, WatchedJsonFile}; @@ -595,7 +595,11 @@ pub fn default_item_factory( let working_directory = get_working_directory(workspace, cx, strategy); let terminal_handle = cx.add_view(|cx| { - TerminalContainer::new(working_directory, false, workspace.database_id(), cx) + TerminalContainer::new( + Err(anyhow!("Don't have a project to open a terminal")), + workspace.database_id(), + cx, + ) }); Box::new(terminal_handle) }