task: Add re-run task button to terminal title (#12379)

Release Notes:

- Added re-run task button to terminal title.

Close #12277

## Demo


https://github.com/zed-industries/zed/assets/5518/4cd05fa5-4255-412b-8583-68e22f86561e

---------

Co-authored-by: Piotr Osiewicz <piotr@zed.dev>
This commit is contained in:
Jason Lee 2024-05-29 17:40:43 +08:00 committed by GitHub
parent 36d0b71f27
commit 3c6c850390
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 77 additions and 16 deletions

View file

@ -24,7 +24,7 @@ use terminal::{
Clear, Copy, Event, MaybeNavigationTarget, Paste, ShowCharacterPalette, TaskStatus, Terminal,
};
use terminal_element::TerminalElement;
use ui::{h_flex, prelude::*, ContextMenu, Icon, IconName, Label};
use ui::{h_flex, prelude::*, ContextMenu, Icon, IconName, Label, Tooltip};
use util::{paths::PathLikeWithPosition, ResultExt};
use workspace::{
item::{BreadcrumbText, Item, ItemEvent, TabContentParams},
@ -787,23 +787,58 @@ impl Item for TerminalView {
fn tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement {
let terminal = self.terminal().read(cx);
let title = terminal.title(true);
let (icon, icon_color) = match terminal.task() {
let (icon, icon_color, rerun_btn) = match terminal.task() {
Some(terminal_task) => match &terminal_task.status {
TaskStatus::Unknown => (IconName::ExclamationTriangle, Color::Warning),
TaskStatus::Running => (IconName::Play, Color::Default),
TaskStatus::Unknown => (IconName::ExclamationTriangle, Color::Warning, None),
TaskStatus::Running => (IconName::Play, Color::Disabled, None),
TaskStatus::Completed { success } => {
let task_id = terminal_task.id.clone();
let rerun_btn = IconButton::new("rerun-icon", IconName::Rerun)
.icon_size(IconSize::Small)
.size(ButtonSize::Compact)
.icon_color(Color::Default)
.shape(ui::IconButtonShape::Square)
.tooltip(|cx| Tooltip::text("Rerun task", cx))
.on_click(move |_, cx| {
cx.dispatch_action(Box::new(tasks_ui::Rerun {
task_id: Some(task_id.clone()),
..Default::default()
}));
});
if *success {
(IconName::Check, Color::Success)
(IconName::Check, Color::Success, Some(rerun_btn))
} else {
(IconName::XCircle, Color::Error)
(IconName::XCircle, Color::Error, Some(rerun_btn))
}
}
},
None => (IconName::Terminal, Color::Muted),
None => (IconName::Terminal, Color::Muted, None),
};
h_flex()
.gap_2()
.child(Icon::new(icon).color(icon_color))
.group("term-tab-icon")
.child(
h_flex()
.group("term-tab-icon")
.child(
div()
.when(rerun_btn.is_some(), |this| {
this.hover(|style| style.invisible().w_0())
})
.child(Icon::new(icon).color(icon_color)),
)
.when_some(rerun_btn, |this, rerun_btn| {
this.child(
div()
.absolute()
.visible_on_hover("term-tab-icon")
.child(rerun_btn),
)
}),
)
.child(Label::new(title).color(if params.selected {
Color::Default
} else {