use std::collections::HashSet;
use super::columns::{COLUMNS, Cell};
use super::{StepDetail, StepSummary, StepsView};
use crate::git_tree::Framing;
use crate::theme;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StepTab {
Meta,
Request,
Staging,
Response,
Tools,
}
pub fn render(
ui: &mut egui::Ui,
view: &StepsView,
selected: Option<usize>,
detail: Option<&StepDetail>,
tab: StepTab,
collapsed: &mut HashSet<String>,
raw: bool,
) {
crate::tail::scroll(ui, detail.is_none(), |ui| {
if view.steps.is_empty() {
ui.label("(no steps yet)");
} else {
render_table(ui, view, selected);
}
if let Some(detail) = detail {
ui.separator();
super::drill::render_detail(ui, detail, tab, collapsed, raw);
}
});
}
fn render_table(ui: &mut egui::Ui, view: &StepsView, selected: Option<usize>) {
egui::Grid::new("steps-table")
.striped(true)
.max_col_width(cell_cap(ui))
.show(ui, |ui| {
for column in COLUMNS {
ui.label(egui::RichText::new(column.header).strong())
.on_hover_text(column.hint);
}
ui.end_row();
for (i, step) in view.steps.iter().enumerate() {
for column in COLUMNS {
paint_cell(ui, (column.cell)(step, Some(i) == selected));
}
ui.end_row();
}
});
}
fn cell_cap(ui: &egui::Ui) -> f32 {
let columns = f32::from(u16::try_from(COLUMNS.len()).unwrap_or(u16::MAX));
let gaps = ui.spacing().item_spacing.x * (columns - 1.0);
((ui.available_width() - gaps) / columns).max(1.0)
}
fn paint_cell(ui: &mut egui::Ui, cell: Cell) {
match cell {
Cell::Colored(color, text) => ui.colored_label(color, text),
Cell::Mono(text) => ui.monospace(text),
Cell::Plain(text) => ui.label(text),
Cell::Weak(text) => ui.weak(text),
Cell::Empty => ui.label(""),
};
}
pub(super) fn summary_badge(step: &StepSummary) -> (&'static str, egui::Color32, &'static str) {
if step.wound.wounded() {
("✖", theme::ICHOR, super::NO_RESPONSE)
} else {
framing_badge(step.framing)
}
}
pub(super) fn framing_badge(framing: Framing) -> (&'static str, egui::Color32, &'static str) {
match framing {
Framing::Complete => ("✔", theme::HYDRA, "complete"),
Framing::Failed => ("✖", theme::ICHOR, "failed"),
Framing::Killed => ("■", theme::ASH, "no clean end"),
}
}