use ratatui::{
style::{Modifier, Style},
text::{Line, Span},
};
use crate::i18n;
use crate::state::AppState;
use crate::state::modal::PreflightHeaderChips;
use crate::theme::theme;
pub mod extract;
pub mod layout;
pub mod scroll;
pub mod sync;
pub mod tabs;
pub mod widget;
pub use crate::ui::helpers::{format_bytes, format_signed_bytes};
pub fn format_count_with_indicator(count: usize, total_items: usize, is_resolving: bool) -> String {
if !is_resolving {
format!("{count}")
} else if count < total_items {
format!("{count}...")
} else {
format!("{count}")
}
}
pub fn render_header_chips(app: &AppState, chips: &PreflightHeaderChips) -> Line<'static> {
let th = theme();
let mut spans = Vec::new();
let package_count = chips.package_count;
let aur_count = chips.aur_count;
let pkg_text = if aur_count > 0 {
format!("{package_count} ({aur_count} AUR)")
} else {
format!("{package_count}")
};
spans.push(Span::styled(
format!("[{pkg_text}]"),
Style::default()
.fg(th.sapphire)
.add_modifier(Modifier::BOLD),
));
spans.push(Span::styled(" ", Style::default()));
spans.push(Span::styled(
i18n::t_fmt1(
app,
"app.modals.preflight.header_chips.download_label",
format_bytes(chips.download_bytes),
),
Style::default().fg(th.sapphire),
));
spans.push(Span::styled(" ", Style::default()));
let delta_color = match chips.install_delta_bytes.cmp(&0) {
std::cmp::Ordering::Greater => th.green,
std::cmp::Ordering::Less => th.red,
std::cmp::Ordering::Equal => th.overlay1, };
spans.push(Span::styled(
i18n::t_fmt1(
app,
"app.modals.preflight.header_chips.size_label",
format_signed_bytes(chips.install_delta_bytes),
),
Style::default().fg(delta_color),
));
spans.push(Span::styled(" ", Style::default()));
let risk_label = match chips.risk_level {
crate::state::modal::RiskLevel::Low => {
i18n::t(app, "app.modals.preflight.header_chips.risk_low")
}
crate::state::modal::RiskLevel::Medium => {
i18n::t(app, "app.modals.preflight.header_chips.risk_medium")
}
crate::state::modal::RiskLevel::High => {
i18n::t(app, "app.modals.preflight.header_chips.risk_high")
}
};
let risk_color = match chips.risk_level {
crate::state::modal::RiskLevel::Low => th.green,
crate::state::modal::RiskLevel::Medium => th.yellow,
crate::state::modal::RiskLevel::High => th.red,
};
spans.push(Span::styled(
format!("[Risk: {} ({})]", risk_label, chips.risk_score),
Style::default().fg(risk_color).add_modifier(Modifier::BOLD),
));
Line::from(spans)
}
#[cfg(test)]
mod format_tests;
#[cfg(test)]
mod layout_tests;
#[cfg(test)]
mod render_tests;
#[cfg(test)]
mod sync_dependencies_tests;
#[cfg(test)]
mod sync_files_tests;
#[cfg(test)]
mod sync_sandbox_tests;
#[cfg(test)]
mod sync_services_tests;