diff --git a/crates/project/src/terminals.rs b/crates/project/src/terminals.rs index cd64793603..66f625a50f 100644 --- a/crates/project/src/terminals.rs +++ b/crates/project/src/terminals.rs @@ -273,6 +273,7 @@ impl Project { status: TaskStatus::Running, show_summary: spawn_task.show_summary, show_command: spawn_task.show_command, + show_rerun: spawn_task.show_rerun, completion_rx, }); diff --git a/crates/task/src/lib.rs b/crates/task/src/lib.rs index 0470e1e3a2..70e6597a43 100644 --- a/crates/task/src/lib.rs +++ b/crates/task/src/lib.rs @@ -58,6 +58,8 @@ pub struct SpawnInTerminal { pub show_summary: bool, /// Whether to show the command line in the task output. pub show_command: bool, + /// Whether to show the rerun button in the terminal tab. + pub show_rerun: bool, } /// A final form of the [`TaskTemplate`], that got resolved with a particular [`TaskContext`] and now is ready to spawn the actual task. diff --git a/crates/task/src/task_template.rs b/crates/task/src/task_template.rs index a25e407f10..84f762638c 100644 --- a/crates/task/src/task_template.rs +++ b/crates/task/src/task_template.rs @@ -255,6 +255,7 @@ impl TaskTemplate { shell: self.shell.clone(), show_summary: self.show_summary, show_command: self.show_command, + show_rerun: true, }), }) } diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 4658eb3643..e256366fe4 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -643,6 +643,7 @@ pub struct TaskState { pub hide: HideStrategy, pub show_summary: bool, pub show_command: bool, + pub show_rerun: bool, } /// A status of the current terminal tab's task. diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index bf371773b7..203620a5cb 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -22,8 +22,8 @@ use terminal::{ }, terminal_settings::{self, CursorShape, TerminalBlink, TerminalSettings, WorkingDirectory}, Clear, Copy, Event, MaybeNavigationTarget, Paste, ScrollLineDown, ScrollLineUp, ScrollPageDown, - ScrollPageUp, ScrollToBottom, ScrollToTop, ShowCharacterPalette, TaskStatus, Terminal, - TerminalBounds, ToggleViMode, + ScrollPageUp, ScrollToBottom, ScrollToTop, ShowCharacterPalette, TaskState, TaskStatus, + Terminal, TerminalBounds, ToggleViMode, }; use terminal_element::{is_blank, TerminalElement}; use terminal_panel::TerminalPanel; @@ -807,6 +807,33 @@ impl TerminalView { .children(Scrollbar::vertical(self.scrollbar_state.clone())), ) } + + fn rerun_button(task: &TaskState) -> Option { + if !task.show_rerun { + return None; + } + + let task_id = task.id.clone(); + Some( + IconButton::new("rerun-icon", IconName::Rerun) + .icon_size(IconSize::Small) + .size(ButtonSize::Compact) + .icon_color(Color::Default) + .shape(ui::IconButtonShape::Square) + .tooltip(Tooltip::text("Rerun task")) + .on_click(move |_, window, cx| { + window.dispatch_action( + Box::new(zed_actions::Rerun { + task_id: Some(task_id.0.clone()), + allow_concurrent_runs: Some(true), + use_new_terminal: Some(false), + reevaluate_context: false, + }), + cx, + ); + }), + ) + } } fn subscribe_for_terminal_events( @@ -1220,44 +1247,26 @@ impl Item for TerminalView { fn tab_content(&self, params: TabContentParams, _window: &Window, cx: &App) -> AnyElement { let terminal = self.terminal().read(cx); let title = terminal.title(true); - let rerun_button = |task_id: task::TaskId| { - IconButton::new("rerun-icon", IconName::Rerun) - .icon_size(IconSize::Small) - .size(ButtonSize::Compact) - .icon_color(Color::Default) - .shape(ui::IconButtonShape::Square) - .tooltip(Tooltip::text("Rerun task")) - .on_click(move |_, window, cx| { - window.dispatch_action( - Box::new(zed_actions::Rerun { - task_id: Some(task_id.0.clone()), - allow_concurrent_runs: Some(true), - use_new_terminal: Some(false), - reevaluate_context: false, - }), - cx, - ); - }) - }; let (icon, icon_color, rerun_button) = match terminal.task() { Some(terminal_task) => match &terminal_task.status { TaskStatus::Running => ( IconName::Play, Color::Disabled, - Some(rerun_button(terminal_task.id.clone())), + TerminalView::rerun_button(&terminal_task), ), TaskStatus::Unknown => ( IconName::Warning, Color::Warning, - Some(rerun_button(terminal_task.id.clone())), + TerminalView::rerun_button(&terminal_task), ), TaskStatus::Completed { success } => { - let rerun_button = rerun_button(terminal_task.id.clone()); + let rerun_button = TerminalView::rerun_button(&terminal_task); + if *success { - (IconName::Check, Color::Success, Some(rerun_button)) + (IconName::Check, Color::Success, rerun_button) } else { - (IconName::XCircle, Color::Error, Some(rerun_button)) + (IconName::XCircle, Color::Error, rerun_button) } } }, diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rs index 2c3b028f56..88adcb1855 100644 --- a/crates/vim/src/command.rs +++ b/crates/vim/src/command.rs @@ -1420,11 +1420,11 @@ impl ShellExec { cx.emit(workspace::Event::SpawnTask { action: Box::new(SpawnInTerminal { id: TaskId("vim".to_string()), - full_label: self.command.clone(), - label: self.command.clone(), + full_label: command.clone(), + label: command.clone(), command: command.clone(), args: Vec::new(), - command_label: self.command.clone(), + command_label: command.clone(), cwd, env: HashMap::default(), use_new_terminal: true, @@ -1435,6 +1435,7 @@ impl ShellExec { shell, show_summary: false, show_command: false, + show_rerun: false, }), }); });