diff --git a/crates/terminal/src/modal.rs b/crates/terminal/src/modal.rs index 00f338825b..f272ccb3d4 100644 --- a/crates/terminal/src/modal.rs +++ b/crates/terminal/src/modal.rs @@ -32,7 +32,7 @@ pub fn deploy_modal(workspace: &mut Workspace, _: &DeployModal, cx: &mut ViewCon if let Some(closed_terminal_handle) = workspace.toggle_modal(cx, |workspace, cx| { let wd = get_wd_for_workspace(workspace, cx); - let this = cx.add_view(|cx| TerminalView::new(wd, true, cx)); + let this = cx.add_view(|cx| TerminalView::new(wd, true, cx).unwrap()); let connection_handle = this.read(cx).connection.0.as_ref().unwrap().clone(); cx.subscribe(&connection_handle, on_event).detach(); diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 28943a1fbb..d47b4fa961 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -82,7 +82,11 @@ impl Entity for TerminalView { impl TerminalView { ///Create a new Terminal view. This spawns a task, a thread, and opens the TTY devices ///To get the right working directory from a workspace, use: `get_wd_for_workspace()` - fn new(working_directory: Option, modal: bool, cx: &mut ViewContext) -> Self { + fn new( + working_directory: Option, + modal: bool, + cx: &mut ViewContext, + ) -> Option { //The details here don't matter, the terminal will be resized on the first layout let size_info = TerminalDimensions::new( DEBUG_LINE_HEIGHT, @@ -103,7 +107,15 @@ impl TerminalView { } }); - TerminalView::from_connection(TerminalConnection(connection), modal, cx) + if let Ok(_) = connection { + Some(TerminalView::from_connection( + TerminalConnection(connection), + modal, + cx, + )) + } else { + None + } } fn from_connection( @@ -150,8 +162,9 @@ impl TerminalView { ///Create a new Terminal in the current working directory or the user's home directory fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext) { let wd = get_wd_for_workspace(workspace, cx); - let view = cx.add_view(|cx| TerminalView::new(wd, false, cx)); - workspace.add_item(Box::new(view), cx); + if let Some(view) = cx.add_option_view(|cx| TerminalView::new(wd, false, cx)) { + workspace.add_item(Box::new(view), cx); + } } fn clear(&mut self, _: &Clear, cx: &mut ViewContext) { @@ -327,7 +340,7 @@ impl Item for TerminalView { Err(e) => e.directory.clone(), }; - Some(TerminalView::new(wd, false, cx)) + TerminalView::new(wd, false, cx) } fn project_path(&self, _cx: &gpui::AppContext) -> Option {