diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index 979bd74..8de3681 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -614,6 +614,8 @@ pub struct Yumush { pending_backup_delete: Option, update: crate::update::Phase, desk: builder::releases::Desk, + log_search: Entity, + log_scroll: gpui_kit::UniformListScrollHandle, share_apps: Vec, share_apps_seen: std::cell::Cell, share_apps_task: Option>, @@ -690,6 +692,7 @@ impl Yumush { let server = network.server(); let account_filter = new_input(w().auth.find_account, window, cx); + let log_search = new_input(w().chat.find, window, cx); cx.subscribe(&account_filter, |_, _, event: &InputEvent, cx| { if matches!(event, InputEvent::Change) { cx.notify(); @@ -716,6 +719,8 @@ impl Yumush { pending_backup_delete: None, update: crate::update::Phase::Idle, desk: builder::releases::Desk::default(), + log_search, + log_scroll: gpui_kit::UniformListScrollHandle::new(), share_apps: Vec::new(), share_apps_seen: std::cell::Cell::new(Instant::now()), share_apps_task: None, diff --git a/crates/client/src/gui/builder/releases.rs b/crates/client/src/gui/builder/releases.rs index a6682df..eb76a50 100644 --- a/crates/client/src/gui/builder/releases.rs +++ b/crates/client/src/gui/builder/releases.rs @@ -3,10 +3,12 @@ use common::{ model::{ReleaseInfo, Staged}, }; use gpui_kit::{ - Anchor, AnyElement, Context, Div, Entity, Hsla, IntoElement, ParentElement, PathPromptOptions, + Anchor, AnyElement, App, Context, Div, Entity, Focusable, Hsla, InteractiveElement, + IntoElement, ListHorizontalSizingBehavior, ParentElement, PathPromptOptions, ScrollStrategy, Styled, Window, component::popover::Popover, div, px, uniform_list, }; use std::path::PathBuf; +use std::rc::Rc; use std::time::{Duration, Instant}; use super::ui::{card, card_header, confirmed, delete_icon_button, list_row, rows_body}; @@ -24,6 +26,8 @@ use crate::lang::w; use crate::release::{Build, Event, Job, LANES, Lane, Level, is_source}; const METER: f32 = 140.; +const LOG_LINE: f32 = 18.; +const LOG_MAX: usize = 50_000; const TICK: Duration = Duration::from_secs(1); #[derive(Default)] @@ -40,12 +44,14 @@ pub(crate) struct Desk { began: Option, ended: Option, dismissed: bool, + log_open: Option, } struct Row { job: Job, phase: Phase, line: String, + log: Vec, started: Option, ended: Option, } @@ -211,7 +217,13 @@ pub(super) fn meter(share: f32, label: String, palette: Palette) -> Div { .child(caption_text(label, palette.muted)) } -fn job_row(row: &Row, seconds: bool, retry: Option, palette: Palette) -> Div { +fn job_row( + row: &Row, + seconds: bool, + retry: Option, + entity: &Entity, + palette: Palette, +) -> Div { let (status, detail): (Div, Option
) = match &row.phase { Phase::Waiting => ( caption_text(w().builder_release.waiting, palette.muted), @@ -240,20 +252,30 @@ fn job_row(row: &Row, seconds: bool, retry: Option, palette: Palette ), }; - list_row() + let info = div() + .id(format!("job_log_{:?}", row.job)) + .w_full() + .flex() + .flex_col() + .cursor_pointer() .child( div() - .flex_1() - .min_w_0() - .flex() - .flex_col() - .child( - div() - .text_size(text(text::LABEL)) - .text_color(palette.text) - .child(job_label(row.job)), - ) - .children(detail.map(|detail| detail.truncate())), + .text_size(text(text::LABEL)) + .text_color(palette.text) + .child(job_label(row.job)), + ) + .children(detail.map(|detail| detail.truncate())); + let job = row.job; + let entity = entity.clone(); + list_row() + .child( + div().flex_1().min_w_0().child( + Popover::new(format!("job_log_popover_{job:?}")) + .anchor(Anchor::TopLeft) + .appearance(false) + .trigger(Trigger::new(info)) + .content(move |_, window, cx| log_sheet(job, &entity, window, cx)), + ), ) .children(retry) .child(status) @@ -262,6 +284,75 @@ fn job_row(row: &Row, seconds: bool, retry: Option, palette: Palette ) } +fn log_sheet(job: Job, entity: &Entity, window: &mut Window, cx: &mut App) -> Div { + let palette = crate::gui::palette(cx); + let input = entity.read(cx).log_search.clone(); + if !input.read(cx).focus_handle(cx).contains_focused(window, cx) { + input.update(cx, |state, cx| state.focus(window, cx)); + } + let query = crate::gui::widget::search_text(&input, cx); + let yumush = entity.read(cx); + let lines: Rc> = Rc::new( + yumush + .desk + .jobs + .iter() + .find(|row| row.job == job) + .map(|row| { + row.log + .iter() + .enumerate() + .filter(|(_, line)| query.is_empty() || line.to_lowercase().contains(&query)) + .map(|(index, _)| index) + .collect() + }) + .unwrap_or_default(), + ); + let scroll = yumush.log_scroll.clone(); + let count = lines.len(); + if yumush.desk.log_open != Some(job) { + scroll.scroll_to_item(count.saturating_sub(1), ScrollStrategy::Bottom); + entity.update(cx, |yumush, _| yumush.desk.log_open = Some(job)); + } + let entity = entity.clone(); + crate::gui::widget::panel(palette) + .w(px(size::PAGE - space::XL)) + .p(px(space::XS)) + .flex() + .flex_col() + .gap(px(space::XS)) + .child(crate::gui::sidebar::input_box(&input, palette)) + .child( + uniform_list( + format!("job_log_lines_{job:?}"), + count, + move |range, _, cx| { + let yumush = entity.read(cx); + let palette = crate::gui::palette(cx); + let Some(row) = yumush.desk.jobs.iter().find(|row| row.job == job) else { + return Vec::new(); + }; + lines[range] + .iter() + .filter_map(|&index| row.log.get(index)) + .map(|line| { + div() + .h(px(LOG_LINE)) + .px(px(space::XS)) + .whitespace_nowrap() + .text_size(text(text::CAPTION)) + .text_color(palette.muted) + .child(line.clone()) + }) + .collect() + }, + ) + .with_horizontal_sizing_behavior(ListHorizontalSizingBehavior::Unconstrained) + .track_scroll(&scroll) + .h(px((count as f32 * LOG_LINE).clamp(LOG_LINE, size::SHEET))), + ) +} + fn draft_row(draft: &Draft, duplicate: bool, entity: &Entity, palette: Palette) -> Div { let id = draft.id; let status = match &draft.stage { @@ -545,12 +636,7 @@ impl Yumush { .child(div().text_color(palette.muted).child(aside)) } - fn lanes( - &self, - entity: &Entity, - fit: impl Fn(Div) -> Div, - palette: Palette, - ) -> Vec
{ + fn lanes(&self, entity: &Entity, fit: impl Fn(Div) -> Div, palette: Palette) -> Vec
{ let seconds = self.settings.clock_seconds; LANES .iter() @@ -570,7 +656,7 @@ impl Yumush { .filter(|row| jobs.contains(&row.job)) .map(|row| { let retry = self.retry_button(row, entity, palette); - fit(job_row(row, seconds, retry, palette).pl(px(space::XL))) + fit(job_row(row, seconds, retry, entity, palette).pl(px(space::XL))) }), ) }) @@ -860,6 +946,7 @@ impl Yumush { job, phase: Phase::Waiting, line: String::new(), + log: Vec::new(), started: None, ended: None, }) @@ -915,13 +1002,22 @@ impl Yumush { } Event::Line(job, line) => { if let Some(row) = self.desk.row(job) { + if row.log.len() >= LOG_MAX { + row.log.drain(..LOG_MAX / 10); + } + row.log.push(line.clone()); row.line = line; } } Event::Built(_, path) => self.stage_release_file(path, window, cx), Event::Finished(job) => self.set_phase(job, Phase::Done), Event::Skipped(job, reason) => self.set_phase(job, Phase::Skipped(reason)), - Event::Failed(job, reason) => self.set_phase(job, Phase::Failed(reason)), + Event::Failed(job, reason) => { + if let Some(row) = self.desk.row(job) { + row.log.push(reason.clone()); + } + self.set_phase(job, Phase::Failed(reason)) + } Event::Done => { self.desk.build = None; self.desk.ended = Some(Instant::now());