boot-tree: palette options, finished-run timeline, readable unit names, repaint on reconnect, handover frame
This commit is contained in:
1 parent
1482d4437a
commit
101d7bae89
16 files changed
+854
-292
No files matched your search
+4
-1
@@ -22,9 +22,10 @@ const SILENT_STATUS: &str = "no";
|
||||
const CONFIGURED_STATUS: &str = "";
|
||||
|
||||
pub struct Feed {
|
||||
pub connections: u32,
|
||||
scope: Scope,
|
||||
target: Option<String>,
|
||||
session: Option<Session>,
|
||||
pub session: Option<Session>,
|
||||
unit_paths: HashMap<Path<'static>, String>,
|
||||
in_initrd: bool,
|
||||
sysroot: Option<Sysroot>,
|
||||
@@ -35,6 +36,7 @@ pub struct Feed {
|
||||
impl Feed {
|
||||
pub fn new(scope: Scope, target: Option<String>) -> Self {
|
||||
Self {
|
||||
connections: 0,
|
||||
in_initrd: scope == Scope::System && FilePath::new(INITRD_RELEASE).exists(),
|
||||
scope,
|
||||
target,
|
||||
@@ -66,6 +68,7 @@ impl Feed {
|
||||
match self.connect(state) {
|
||||
Ok(session) => {
|
||||
self.session = Some(session);
|
||||
self.connections += 1;
|
||||
Ok(())
|
||||
}
|
||||
Err(_) if Instant::now() < self.reconnect_deadline => {
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod model;
|
||||
pub mod palette;
|
||||
pub mod view;
|
||||
+32
-6
@@ -6,9 +6,11 @@ mod run;
|
||||
mod sysroot;
|
||||
mod systemd;
|
||||
|
||||
use std::{process::ExitCode, time::Duration};
|
||||
use std::{fs, io::ErrorKind, path::PathBuf, process::ExitCode, time::Duration};
|
||||
|
||||
use boot_tree::palette::Config;
|
||||
use clap::Parser;
|
||||
use jiff::SignedDuration;
|
||||
|
||||
use crate::{
|
||||
run::{Options, run},
|
||||
@@ -27,20 +29,44 @@ struct Cli {
|
||||
target: Option<String>,
|
||||
#[arg(
|
||||
long,
|
||||
default_value_t = 0,
|
||||
help = "Milliseconds to keep the final frame on screen"
|
||||
default_value = "1s",
|
||||
value_parser = parse_duration,
|
||||
help = "How long the final frame stays on screen, e.g. 1s or 500ms"
|
||||
)]
|
||||
hold_ms: u64,
|
||||
hold: Duration,
|
||||
#[arg(
|
||||
long,
|
||||
default_value = "/etc/boot-tree.toml",
|
||||
help = "TOML file with a [palette] table"
|
||||
)]
|
||||
config: PathBuf,
|
||||
}
|
||||
|
||||
fn parse_duration(raw: &str) -> Result<Duration, String> {
|
||||
let signed: SignedDuration = raw.parse().map_err(|error| format!("{error}"))?;
|
||||
Duration::try_from(signed).map_err(|error| format!("{error}"))
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let cli = Cli::parse();
|
||||
let config = match fs::read_to_string(&cli.config) {
|
||||
Ok(text) => toml::from_str(&text).unwrap_or_else(|error| {
|
||||
eprintln!("boot-tree: ignoring {}: {error}", cli.config.display());
|
||||
Config::default()
|
||||
}),
|
||||
Err(error) if error.kind() == ErrorKind::NotFound => Config::default(),
|
||||
Err(error) => {
|
||||
eprintln!("boot-tree: cannot read {}: {error}", cli.config.display());
|
||||
Config::default()
|
||||
}
|
||||
};
|
||||
let options = Options {
|
||||
scope: if cli.user { Scope::User } else { Scope::System },
|
||||
target: cli.target,
|
||||
hold: Duration::from_millis(cli.hold_ms),
|
||||
hold: cli.hold,
|
||||
palette: config.palette,
|
||||
};
|
||||
match run(options) {
|
||||
match run(&options) {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
Err(error) => {
|
||||
eprintln!("boot-tree: {error}");
|
||||
|
||||
+43
-4
@@ -87,6 +87,7 @@ pub struct Activity {
|
||||
struct PendingJob {
|
||||
id: u32,
|
||||
queued_at: Duration,
|
||||
brings_up: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -162,6 +163,14 @@ pub struct Tally {
|
||||
pub failed: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct FinishedRun {
|
||||
pub label: String,
|
||||
pub started_at: Duration,
|
||||
pub finished_at: Duration,
|
||||
pub failed: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct FinishedStage {
|
||||
pub label: &'static str,
|
||||
@@ -177,8 +186,9 @@ pub struct BootState {
|
||||
pub root: Option<String>,
|
||||
pub failed: Vec<String>,
|
||||
pub finished_stages: Vec<FinishedStage>,
|
||||
pub finished_runs: Vec<FinishedRun>,
|
||||
pub handoff_unit: Option<String>,
|
||||
root_job_seen: bool,
|
||||
handoff_unit: Option<String>,
|
||||
milestone_targets: Vec<String>,
|
||||
finished_before_reconnect: usize,
|
||||
units: HashMap<String, UnitRecord>,
|
||||
@@ -210,6 +220,7 @@ impl BootState {
|
||||
root: None,
|
||||
failed: Vec::new(),
|
||||
finished_stages: Vec::new(),
|
||||
finished_runs: Vec::new(),
|
||||
root_job_seen: false,
|
||||
handoff_unit,
|
||||
milestone_targets,
|
||||
@@ -258,7 +269,7 @@ impl BootState {
|
||||
}
|
||||
|
||||
pub fn queue_job(&mut self, id: u32, unit: &str, at: Duration) {
|
||||
self.queue_job_of_unknown_kind(id, unit, at);
|
||||
self.enqueue(id, unit, at, true);
|
||||
if self.jobs.get(&id).is_some_and(|tracked| tracked == unit)
|
||||
&& self.root.as_deref() == Some(unit)
|
||||
{
|
||||
@@ -267,13 +278,21 @@ impl BootState {
|
||||
}
|
||||
|
||||
pub fn queue_job_of_unknown_kind(&mut self, id: u32, unit: &str, at: Duration) {
|
||||
self.enqueue(id, unit, at, false);
|
||||
}
|
||||
|
||||
fn enqueue(&mut self, id: u32, unit: &str, at: Duration, brings_up: bool) {
|
||||
if self.jobs.contains_key(&id) {
|
||||
return;
|
||||
}
|
||||
let Some(record) = self.units.get_mut(unit) else {
|
||||
return;
|
||||
};
|
||||
record.job = Some(PendingJob { id, queued_at: at });
|
||||
record.job = Some(PendingJob {
|
||||
id,
|
||||
queued_at: at,
|
||||
brings_up,
|
||||
});
|
||||
record.outcome = None;
|
||||
self.jobs.insert(id, unit.to_owned());
|
||||
}
|
||||
@@ -285,9 +304,26 @@ impl BootState {
|
||||
let Some(record) = self.units.get_mut(&unit) else {
|
||||
return;
|
||||
};
|
||||
let started_at = record
|
||||
.inactive_exit
|
||||
.filter(|started| *started >= self.origin && *started <= at)
|
||||
.filter(|_| record.job.is_some_and(|job| job.id == id && job.brings_up));
|
||||
if record.job.is_some_and(|job| job.id == id) {
|
||||
record.job = None;
|
||||
}
|
||||
if let Some(started_at) = started_at
|
||||
&& !record.facts.name.ends_with(".target")
|
||||
{
|
||||
self.finished_runs.push(FinishedRun {
|
||||
label: display_label(&record.facts),
|
||||
started_at,
|
||||
finished_at: at,
|
||||
failed: matches!(
|
||||
result,
|
||||
JobResult::Failed | JobResult::Timeout | JobResult::Dependency
|
||||
),
|
||||
});
|
||||
}
|
||||
let outcome = match result {
|
||||
JobResult::Done => Outcome::Succeeded { at },
|
||||
JobResult::Skipped | JobResult::Canceled => Outcome::Abandoned,
|
||||
@@ -611,7 +647,10 @@ fn display_label(facts: &UnitFacts) -> String {
|
||||
if let Some(stem) = facts.name.strip_suffix(".service") {
|
||||
return stem.to_owned();
|
||||
}
|
||||
if facts.name.ends_with(".device") && !facts.description.is_empty() {
|
||||
let described_by_path = [".device", ".mount", ".swap", ".automount"]
|
||||
.iter()
|
||||
.any(|suffix| facts.name.ends_with(suffix));
|
||||
if described_by_path && !facts.description.is_empty() {
|
||||
return facts.description.clone();
|
||||
}
|
||||
facts.name.clone()
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
use ratatui::style::Color;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct Palette {
|
||||
pub text: Color,
|
||||
pub muted: Color,
|
||||
pub waiting: Color,
|
||||
pub running: Color,
|
||||
pub done: Color,
|
||||
pub failed: Color,
|
||||
pub target: Color,
|
||||
}
|
||||
|
||||
impl Default for Palette {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
text: Color::White,
|
||||
muted: Color::DarkGray,
|
||||
waiting: Color::Gray,
|
||||
running: Color::Yellow,
|
||||
done: Color::Green,
|
||||
failed: Color::LightRed,
|
||||
target: Color::Cyan,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Eq)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct Config {
|
||||
pub palette: Palette,
|
||||
}
|
||||
+17
-5
@@ -5,11 +5,12 @@ use std::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
thread::sleep,
|
||||
time::Duration,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use boot_tree::{
|
||||
model::{BootState, Phase},
|
||||
palette::Palette,
|
||||
view::BootView,
|
||||
};
|
||||
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyModifiers};
|
||||
@@ -30,15 +31,16 @@ use crate::{
|
||||
};
|
||||
|
||||
const FRAME_INTERVAL: Duration = Duration::from_millis(100);
|
||||
const FRAMES_PER_FULL_REPAINT: u64 = 20;
|
||||
const FULL_REPAINT_INTERVAL: Duration = Duration::from_secs(1);
|
||||
|
||||
pub struct Options {
|
||||
pub scope: Scope,
|
||||
pub target: Option<String>,
|
||||
pub hold: Duration,
|
||||
pub palette: Palette,
|
||||
}
|
||||
|
||||
pub fn run(options: Options) -> Result<(), Error> {
|
||||
pub fn run(options: &Options) -> Result<(), Error> {
|
||||
let terminate = Arc::new(AtomicBool::new(false));
|
||||
flag::register(SIGTERM, Arc::clone(&terminate))?;
|
||||
let phase = match options.scope {
|
||||
@@ -47,7 +49,7 @@ pub fn run(options: Options) -> Result<(), Error> {
|
||||
Scope::System => Phase::Host,
|
||||
};
|
||||
let mut state = BootState::new(phase);
|
||||
let mut feed = Feed::new(options.scope, options.target);
|
||||
let mut feed = Feed::new(options.scope, options.target.clone());
|
||||
let _quiet_kernel = (options.scope == Scope::System)
|
||||
.then(QuietKernelConsole::take)
|
||||
.flatten();
|
||||
@@ -58,6 +60,7 @@ pub fn run(options: Options) -> Result<(), Error> {
|
||||
&mut feed,
|
||||
&mut terminal,
|
||||
&terminate,
|
||||
&options.palette,
|
||||
options.hold,
|
||||
);
|
||||
ratatui::restore();
|
||||
@@ -80,20 +83,29 @@ fn watch(
|
||||
feed: &mut Feed,
|
||||
terminal: &mut DefaultTerminal,
|
||||
terminate: &AtomicBool,
|
||||
palette: &Palette,
|
||||
hold: Duration,
|
||||
) -> Result<(), Error> {
|
||||
let host = uname().nodename().to_string_lossy().into_owned();
|
||||
let mut frame: u64 = 0;
|
||||
let mut painted_connections = feed.connections;
|
||||
let mut last_full_repaint = Instant::now();
|
||||
loop {
|
||||
feed.pump(state, FRAME_INTERVAL)?;
|
||||
if frame.is_multiple_of(FRAMES_PER_FULL_REPAINT) {
|
||||
if feed.session.is_none()
|
||||
|| feed.connections != painted_connections
|
||||
|| last_full_repaint.elapsed() >= FULL_REPAINT_INTERVAL
|
||||
{
|
||||
terminal.backend_mut().clear_region(ClearType::All)?;
|
||||
terminal.swap_buffers();
|
||||
painted_connections = feed.connections;
|
||||
last_full_repaint = Instant::now();
|
||||
}
|
||||
terminal.draw(|canvas| {
|
||||
canvas.render_widget(
|
||||
BootView {
|
||||
state,
|
||||
palette,
|
||||
now: monotonic_now(),
|
||||
host: &host,
|
||||
frame,
|
||||
|
||||
+393
-256
@@ -1,4 +1,5 @@
|
||||
use std::{
|
||||
cmp::Reverse,
|
||||
iter::{once, repeat_n},
|
||||
time::Duration,
|
||||
};
|
||||
@@ -12,7 +13,10 @@ use ratatui::{
|
||||
widgets::{Block, Borders, Paragraph, Row, Table, Widget},
|
||||
};
|
||||
|
||||
use crate::model::{BootState, MilestoneRow, PendingRow, RowStatus, Tally};
|
||||
use crate::{
|
||||
model::{BootState, FinishedRun, MilestoneRow, PendingRow, RowStatus, Tally},
|
||||
palette::Palette,
|
||||
};
|
||||
|
||||
const SPINNER: [char; 4] = ['|', '/', '-', '\\'];
|
||||
const DONE: char = '√';
|
||||
@@ -24,6 +28,7 @@ const RUNNING_MARK: char = '►';
|
||||
const ROOT_SWITCH_MARK: char = '│';
|
||||
const RULE: char = '─';
|
||||
const RULE_STUB: &str = "──";
|
||||
const KERNEL_ORIGIN_LABEL: &str = "kernel";
|
||||
|
||||
const DURATION_WIDTH: u16 = 8;
|
||||
const TIMELINE_LABEL_WIDTH: u16 = 28;
|
||||
@@ -60,31 +65,50 @@ const AXIS_LABEL: SpanPrinter = SpanPrinter::new()
|
||||
|
||||
pub struct BootView<'a> {
|
||||
pub state: &'a BootState,
|
||||
pub palette: &'a Palette,
|
||||
pub now: Duration,
|
||||
pub host: &'a str,
|
||||
pub frame: u64,
|
||||
}
|
||||
|
||||
struct TimelineContent<'a> {
|
||||
milestones: Vec<MilestoneRow>,
|
||||
finished: Vec<&'a FinishedRun>,
|
||||
running: Vec<&'a PendingRow>,
|
||||
}
|
||||
|
||||
impl Widget for BootView<'_> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let rows = self.state.pending_rows();
|
||||
let mut running: Vec<&PendingRow> = rows
|
||||
.iter()
|
||||
.filter(|row| !row.is_target && row.status == RowStatus::Running)
|
||||
.collect();
|
||||
running.sort_by_key(|row| row.running_since);
|
||||
let milestones: Vec<MilestoneRow> = self
|
||||
.state
|
||||
.milestones()
|
||||
.into_iter()
|
||||
.filter(|row| row.reached_at.is_some())
|
||||
.collect();
|
||||
let mut units: Vec<&PendingRow> = rows.iter().filter(|row| !row.is_target).collect();
|
||||
units.sort_by_key(|row| row.running_since.unwrap_or(Duration::MAX));
|
||||
let failures = failure_lines(&self.state.failed);
|
||||
let failures = self.failure_lines();
|
||||
let stages = self.stage_lines(area.width);
|
||||
let stages_height = u16::try_from(stages.len()).unwrap_or(u16::MAX);
|
||||
let failures_height = u16::try_from(failures.len()).unwrap_or(u16::MAX);
|
||||
let fits_timeline = area.width >= TIMELINE_LABEL_WIDTH + 1 + MIN_BAR_WIDTH
|
||||
&& area.height >= MIN_HEIGHT_FOR_TIMELINE;
|
||||
let timeline_entries = milestones.len() + self.state.finished_runs.len() + running.len();
|
||||
let timeline_need = if fits_timeline && timeline_entries > 0 {
|
||||
TIMELINE_CHROME_HEIGHT
|
||||
.saturating_add(u16::try_from(timeline_entries).unwrap_or(u16::MAX))
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let heights = Heights::share(
|
||||
area.height
|
||||
.saturating_sub(HEADER_HEIGHT + stages_height + failures_height + FOOTER_HEIGHT),
|
||||
u16::try_from(rows.len()).unwrap_or(u16::MAX),
|
||||
timeline_need(area, milestones.len() + units.len()),
|
||||
timeline_need,
|
||||
);
|
||||
|
||||
let [header, _, stage_area, tree, failed, _, timeline, footer] = Layout::vertical([
|
||||
@@ -104,15 +128,24 @@ impl Widget for BootView<'_> {
|
||||
self.tree(&rows, tree.height).render(tree, buf);
|
||||
Paragraph::new(failures).render(failed, buf);
|
||||
if heights.timeline > 0 {
|
||||
self.timeline(&milestones, &units, timeline.width)
|
||||
.render(timeline, buf);
|
||||
let bar_rows = usize::from(heights.timeline.saturating_sub(TIMELINE_CHROME_HEIGHT));
|
||||
let finished_room = bar_rows.saturating_sub(milestones.len() + running.len());
|
||||
let mut finished: Vec<&FinishedRun> = self.state.finished_runs.iter().collect();
|
||||
finished.sort_by_key(|run| Reverse(run.finished_at.saturating_sub(run.started_at)));
|
||||
finished.truncate(finished_room);
|
||||
finished.sort_by_key(|run| run.started_at);
|
||||
self.timeline(
|
||||
&TimelineContent {
|
||||
milestones,
|
||||
finished,
|
||||
running,
|
||||
},
|
||||
timeline.width,
|
||||
)
|
||||
.render(timeline, buf);
|
||||
}
|
||||
footer_paragraph(
|
||||
self.state.tally(),
|
||||
footer.width,
|
||||
!self.state.finished_stages.is_empty(),
|
||||
)
|
||||
.render(footer, buf);
|
||||
self.footer(self.state.tally(), footer.width)
|
||||
.render(footer, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,45 +170,63 @@ impl Heights {
|
||||
}
|
||||
}
|
||||
|
||||
fn rule_line(width: u16, left: Vec<Span<'static>>, right: Vec<Span<'static>>) -> Line<'static> {
|
||||
let used = Line::from(left.clone()).width() + Line::from(right.clone()).width();
|
||||
let fill: String = repeat_n(RULE, usize::from(width).saturating_sub(used)).collect();
|
||||
Line::from(
|
||||
left.into_iter()
|
||||
.chain(once(Span::from(fill).dark_gray()))
|
||||
.chain(right)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}
|
||||
|
||||
impl BootView<'_> {
|
||||
fn rule_line(
|
||||
&self,
|
||||
width: u16,
|
||||
left: Vec<Span<'static>>,
|
||||
right: Vec<Span<'static>>,
|
||||
) -> Line<'static> {
|
||||
let used = Line::from(left.clone()).width() + Line::from(right.clone()).width();
|
||||
let fill: String = repeat_n(RULE, usize::from(width).saturating_sub(used)).collect();
|
||||
Line::from(
|
||||
left.into_iter()
|
||||
.chain(once(Span::styled(
|
||||
fill,
|
||||
Style::new().fg(self.palette.muted),
|
||||
)))
|
||||
.chain(right)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}
|
||||
|
||||
fn header(&self) -> Table<'static> {
|
||||
let elapsed =
|
||||
ELAPSED.unsigned_duration_to_string(&self.now.saturating_sub(self.state.origin));
|
||||
let total = (!self.state.finished_stages.is_empty()).then(|| {
|
||||
ELAPSED.unsigned_duration_to_string(&self.now.saturating_sub(self.state.origin))
|
||||
});
|
||||
Table::new(
|
||||
[Row::new([
|
||||
Line::from(format!("boot-tree {}", self.host)),
|
||||
Line::from(elapsed).right_aligned(),
|
||||
Line::from(total.unwrap_or_default()).right_aligned(),
|
||||
])],
|
||||
[Constraint::Fill(1), Constraint::Length(DURATION_WIDTH)],
|
||||
)
|
||||
.style(Style::new().fg(self.palette.text))
|
||||
.bold()
|
||||
}
|
||||
|
||||
fn stage_lines(&self, width: u16) -> Vec<Line<'static>> {
|
||||
let finished = self.state.finished_stages.iter().map(|stage| {
|
||||
rule_line(
|
||||
self.rule_line(
|
||||
width,
|
||||
vec![
|
||||
Span::from(format!("{RULE_STUB} {} {RULE_STUB} ", stage.label)).dark_gray(),
|
||||
Span::from(format!(
|
||||
"{BEAD} done in {}",
|
||||
ELAPSED.unsigned_duration_to_string(
|
||||
&stage.reached_at.saturating_sub(stage.started_at)
|
||||
)
|
||||
))
|
||||
.green(),
|
||||
Span::from(format!(" · {} ", unit_count(stage.finished_units))).dark_gray(),
|
||||
Span::styled(
|
||||
format!("{RULE_STUB} {} {RULE_STUB} ", stage.label),
|
||||
Style::new().fg(self.palette.muted),
|
||||
),
|
||||
Span::styled(
|
||||
format!(
|
||||
"{BEAD} done in {}",
|
||||
ELAPSED.unsigned_duration_to_string(
|
||||
&stage.reached_at.saturating_sub(stage.started_at)
|
||||
)
|
||||
),
|
||||
Style::new().fg(self.palette.done),
|
||||
),
|
||||
Span::styled(
|
||||
format!(" · {} ", unit_count(stage.finished_units)),
|
||||
Style::new().fg(self.palette.waiting),
|
||||
),
|
||||
],
|
||||
Vec::new(),
|
||||
)
|
||||
@@ -185,26 +236,95 @@ impl BootView<'_> {
|
||||
.finished_stages
|
||||
.last()
|
||||
.map_or(self.state.origin, |stage| stage.reached_at);
|
||||
let current = rule_line(
|
||||
width,
|
||||
vec![
|
||||
Span::from(format!("{RULE_STUB} ")).dark_gray(),
|
||||
Span::from(self.state.phase.label()).bold(),
|
||||
Span::raw(" "),
|
||||
],
|
||||
vec![
|
||||
Span::raw(" "),
|
||||
Span::from(
|
||||
ELAPSED
|
||||
.unsigned_duration_to_string(&self.now.saturating_sub(current_started_at)),
|
||||
)
|
||||
.bold(),
|
||||
Span::from(format!(" {RULE_STUB}")).dark_gray(),
|
||||
],
|
||||
);
|
||||
let current = if self.state.is_complete() {
|
||||
let handed_to = self
|
||||
.state
|
||||
.handoff_unit
|
||||
.as_deref()
|
||||
.or(self.state.root.as_deref())
|
||||
.unwrap_or("the console");
|
||||
self.rule_line(
|
||||
width,
|
||||
vec![
|
||||
Span::styled(format!("{RULE_STUB} "), Style::new().fg(self.palette.muted)),
|
||||
Span::styled(
|
||||
format!(
|
||||
"{BEAD} boot finished in {}",
|
||||
ELAPSED.unsigned_duration_to_string(
|
||||
&self.now.saturating_sub(self.state.origin)
|
||||
)
|
||||
),
|
||||
Style::new().fg(self.palette.done).bold(),
|
||||
),
|
||||
Span::styled(
|
||||
format!(" · handing over to {handed_to} "),
|
||||
Style::new().fg(self.palette.text),
|
||||
),
|
||||
],
|
||||
Vec::new(),
|
||||
)
|
||||
} else {
|
||||
self.rule_line(
|
||||
width,
|
||||
vec![
|
||||
Span::styled(format!("{RULE_STUB} "), Style::new().fg(self.palette.muted)),
|
||||
Span::styled(
|
||||
self.state.phase.label(),
|
||||
Style::new().fg(self.palette.text).bold(),
|
||||
),
|
||||
Span::raw(" "),
|
||||
],
|
||||
vec![
|
||||
Span::raw(" "),
|
||||
Span::styled(
|
||||
ELAPSED.unsigned_duration_to_string(
|
||||
&self.now.saturating_sub(current_started_at),
|
||||
),
|
||||
Style::new().fg(self.palette.text).bold(),
|
||||
),
|
||||
Span::styled(format!(" {RULE_STUB}"), Style::new().fg(self.palette.muted)),
|
||||
],
|
||||
)
|
||||
};
|
||||
finished.chain(once(current)).collect()
|
||||
}
|
||||
|
||||
fn failure_lines(&self) -> Vec<Line<'static>> {
|
||||
let units = &self.state.failed;
|
||||
let hidden = units.len().saturating_sub(MAX_FAILED_ROWS);
|
||||
units
|
||||
.iter()
|
||||
.take(MAX_FAILED_ROWS)
|
||||
.map(|unit| format!("{FAILED} {unit} failed"))
|
||||
.chain((hidden > 0).then(|| format!("{FAILED} {hidden} more failed")))
|
||||
.map(|text| Line::styled(text, Style::new().fg(self.palette.failed).bold()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn label_style(&self, row: &PendingRow) -> Style {
|
||||
match (row.is_target, row.status) {
|
||||
(true, _) => Style::new().fg(self.palette.target),
|
||||
(false, RowStatus::Running) => Style::new().fg(self.palette.text),
|
||||
(false, RowStatus::Waiting) => Style::new().fg(self.palette.waiting),
|
||||
}
|
||||
}
|
||||
|
||||
fn status_marker(&self, row: &PendingRow) -> Span<'static> {
|
||||
match (row.is_target, row.status) {
|
||||
(true, _) => Span::raw(""),
|
||||
(false, RowStatus::Running) => {
|
||||
let spinner = SPINNER[usize::try_from(self.frame % 4).unwrap_or_default()];
|
||||
Span::styled(
|
||||
format!("[{spinner}] "),
|
||||
Style::new().fg(self.palette.running),
|
||||
)
|
||||
}
|
||||
(false, RowStatus::Waiting) => {
|
||||
Span::styled("[ ] ", Style::new().fg(self.palette.waiting))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn tree<'a>(&self, rows: &'a [PendingRow], height: u16) -> Table<'a> {
|
||||
let capacity = usize::from(height);
|
||||
let shown = if rows.len() > capacity {
|
||||
@@ -213,8 +333,12 @@ impl BootView<'_> {
|
||||
rows.len()
|
||||
};
|
||||
let hidden = rows.len() - shown;
|
||||
let overflow =
|
||||
(hidden > 0).then(|| Row::new([Line::from(format!("… {hidden} more")).dark_gray()]));
|
||||
let overflow = (hidden > 0).then(|| {
|
||||
Row::new([Line::styled(
|
||||
format!("… {hidden} more"),
|
||||
Style::new().fg(self.palette.waiting),
|
||||
)])
|
||||
});
|
||||
Table::new(
|
||||
rows.iter()
|
||||
.take(shown)
|
||||
@@ -228,22 +352,17 @@ impl BootView<'_> {
|
||||
let since = row.running_since.unwrap_or(row.queued_at);
|
||||
Row::new([
|
||||
Line::from(vec![
|
||||
Span::from(tree_prefix(row)).dark_gray(),
|
||||
status_marker(row, self.frame),
|
||||
Span::styled(row.label.as_str(), label_style(row)),
|
||||
Span::styled(tree_prefix(row), Style::new().fg(self.palette.muted)),
|
||||
self.status_marker(row),
|
||||
Span::styled(row.label.as_str(), self.label_style(row)),
|
||||
]),
|
||||
Line::from(ELAPSED.unsigned_duration_to_string(&self.now.saturating_sub(since)))
|
||||
.style(label_style(row))
|
||||
.style(self.label_style(row))
|
||||
.right_aligned(),
|
||||
])
|
||||
}
|
||||
|
||||
fn timeline<'a>(
|
||||
&self,
|
||||
milestones: &'a [MilestoneRow],
|
||||
units: &[&'a PendingRow],
|
||||
width: u16,
|
||||
) -> Table<'a> {
|
||||
fn timeline<'a>(&self, content: &TimelineContent<'a>, width: u16) -> Table<'a> {
|
||||
let axis = TimeAxis::new(
|
||||
self.state.origin,
|
||||
self.now,
|
||||
@@ -255,36 +374,25 @@ impl BootView<'_> {
|
||||
.iter()
|
||||
.map(|stage| stage.reached_at)
|
||||
.collect();
|
||||
let muted = Style::new().fg(self.palette.muted);
|
||||
let axis_rows = [
|
||||
Row::new([Line::default(), axis.labels()]),
|
||||
Row::new([Line::default(), axis.ticks_line(&root_switches)]),
|
||||
Row::new([Line::default(), axis.labels(muted)]),
|
||||
Row::new([Line::default(), axis.ticks_line(&root_switches, muted)]),
|
||||
];
|
||||
let milestone_rows = milestones.iter().map(|row| {
|
||||
let entries = content
|
||||
.milestones
|
||||
.iter()
|
||||
.map(|row| self.milestone_entry(row))
|
||||
.chain(content.finished.iter().map(|run| self.finished_entry(run)))
|
||||
.chain(content.running.iter().map(|row| self.running_entry(row)));
|
||||
let bar_rows = entries.map(|entry| {
|
||||
Row::new([
|
||||
Line::from(format!(
|
||||
"{DONE} {} ({})",
|
||||
row.label,
|
||||
unit_count(row.finished_units)
|
||||
))
|
||||
.green(),
|
||||
axis.bar(&milestone_segments(row), None, &root_switches),
|
||||
])
|
||||
});
|
||||
let unit_rows = units.iter().map(|row| {
|
||||
Row::new([
|
||||
Line::from(vec![
|
||||
timeline_marker(row),
|
||||
Span::styled(row.label.as_str(), label_style(row)),
|
||||
]),
|
||||
axis.bar(
|
||||
&unit_segments(row, self.now),
|
||||
Some(self.now),
|
||||
&root_switches,
|
||||
),
|
||||
entry.label,
|
||||
axis.bar(&entry.segments, entry.still_going_at, &root_switches, muted),
|
||||
])
|
||||
});
|
||||
Table::new(
|
||||
axis_rows.into_iter().chain(milestone_rows).chain(unit_rows),
|
||||
axis_rows.into_iter().chain(bar_rows),
|
||||
[
|
||||
Constraint::Length(TIMELINE_LABEL_WIDTH),
|
||||
Constraint::Fill(1),
|
||||
@@ -293,65 +401,135 @@ impl BootView<'_> {
|
||||
.block(
|
||||
Block::new()
|
||||
.borders(Borders::TOP)
|
||||
.border_style(Style::new().dark_gray())
|
||||
.title(Line::from(" timeline ").dark_gray()),
|
||||
.border_style(Style::new().fg(self.palette.muted))
|
||||
.title(Line::styled(
|
||||
" timeline ",
|
||||
Style::new().fg(self.palette.waiting),
|
||||
)),
|
||||
)
|
||||
}
|
||||
|
||||
fn milestone_entry(&self, row: &MilestoneRow) -> TimelineEntry<'static> {
|
||||
let done = Style::new().fg(self.palette.done);
|
||||
TimelineEntry {
|
||||
label: Line::styled(
|
||||
format!("{DONE} {} ({})", row.label, unit_count(row.finished_units)),
|
||||
done,
|
||||
),
|
||||
segments: row
|
||||
.reached_at
|
||||
.map(|reached_at| Segment {
|
||||
from: row.started_at,
|
||||
to: reached_at,
|
||||
symbol: BEAD,
|
||||
style: done,
|
||||
})
|
||||
.into_iter()
|
||||
.collect(),
|
||||
still_going_at: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn finished_entry<'a>(&self, run: &'a FinishedRun) -> TimelineEntry<'a> {
|
||||
let (mark, outcome) = if run.failed {
|
||||
(FAILED, Style::new().fg(self.palette.failed))
|
||||
} else {
|
||||
(DONE, Style::new().fg(self.palette.done))
|
||||
};
|
||||
TimelineEntry {
|
||||
label: Line::from(vec![
|
||||
Span::styled(format!("{mark} "), outcome),
|
||||
Span::styled(run.label.as_str(), Style::new().fg(self.palette.waiting)),
|
||||
]),
|
||||
segments: vec![Segment {
|
||||
from: run.started_at,
|
||||
to: run.finished_at,
|
||||
symbol: BEAD,
|
||||
style: outcome,
|
||||
}],
|
||||
still_going_at: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn running_entry<'a>(&self, row: &'a PendingRow) -> TimelineEntry<'a> {
|
||||
let since = row.running_since.unwrap_or(row.queued_at);
|
||||
let waited = (since > row.queued_at).then(|| Segment {
|
||||
from: row.queued_at,
|
||||
to: since,
|
||||
symbol: WAITING_BEAD,
|
||||
style: Style::new().fg(self.palette.waiting),
|
||||
});
|
||||
let ran = Segment {
|
||||
from: since,
|
||||
to: self.now,
|
||||
symbol: BEAD,
|
||||
style: Style::new().fg(self.palette.running),
|
||||
};
|
||||
TimelineEntry {
|
||||
label: Line::from(vec![
|
||||
Span::styled(
|
||||
format!("{RUNNING_MARK} "),
|
||||
Style::new().fg(self.palette.running),
|
||||
),
|
||||
Span::styled(row.label.as_str(), Style::new().fg(self.palette.text)),
|
||||
]),
|
||||
segments: waited.into_iter().chain(once(ran)).collect(),
|
||||
still_going_at: Some(self.now),
|
||||
}
|
||||
}
|
||||
|
||||
fn footer(&self, tally: Tally, width: u16) -> Paragraph<'static> {
|
||||
let failed_style = if tally.failed > 0 {
|
||||
Style::new().fg(self.palette.failed).bold()
|
||||
} else {
|
||||
Style::new().fg(self.palette.waiting)
|
||||
};
|
||||
let counts = vec![
|
||||
Span::styled(
|
||||
format!("{DONE} {} done", tally.done),
|
||||
Style::new().fg(self.palette.done),
|
||||
),
|
||||
Span::styled(
|
||||
format!(" {} running", tally.running),
|
||||
Style::new().fg(self.palette.running),
|
||||
),
|
||||
Span::styled(
|
||||
format!(" {} waiting", tally.waiting),
|
||||
Style::new().fg(self.palette.waiting),
|
||||
),
|
||||
Span::styled(format!(" {FAILED} {} failed", tally.failed), failed_style),
|
||||
];
|
||||
let switch_legend = if self.state.finished_stages.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!(" {ROOT_SWITCH_MARK} root switch")
|
||||
};
|
||||
let legend = format!("{BEAD} running {WAITING_BEAD} waiting{switch_legend}");
|
||||
let used = Line::from(counts.clone()).width() + legend.chars().count();
|
||||
let gap = usize::from(width).saturating_sub(used);
|
||||
let spans = if gap >= 2 {
|
||||
counts
|
||||
.into_iter()
|
||||
.chain([
|
||||
Span::raw(" ".repeat(gap)),
|
||||
Span::styled(legend, Style::new().fg(self.palette.waiting)),
|
||||
])
|
||||
.collect()
|
||||
} else {
|
||||
counts
|
||||
};
|
||||
Paragraph::new(Line::from(spans)).block(
|
||||
Block::new()
|
||||
.borders(Borders::TOP)
|
||||
.border_style(Style::new().fg(self.palette.muted)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn timeline_need(screen: Rect, entries: usize) -> u16 {
|
||||
let fits = screen.width >= TIMELINE_LABEL_WIDTH + 1 + MIN_BAR_WIDTH
|
||||
&& screen.height >= MIN_HEIGHT_FOR_TIMELINE
|
||||
&& entries > 0;
|
||||
if fits {
|
||||
TIMELINE_CHROME_HEIGHT.saturating_add(u16::try_from(entries).unwrap_or(u16::MAX))
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fn failure_lines(units: &[String]) -> Vec<Line<'static>> {
|
||||
let hidden = units.len().saturating_sub(MAX_FAILED_ROWS);
|
||||
units
|
||||
.iter()
|
||||
.take(MAX_FAILED_ROWS)
|
||||
.map(|unit| format!("{FAILED} {unit} failed"))
|
||||
.chain((hidden > 0).then(|| format!("{FAILED} {hidden} more failed")))
|
||||
.map(|text| Line::from(text).red().bold())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn footer_paragraph(tally: Tally, width: u16, root_switched: bool) -> Paragraph<'static> {
|
||||
let counts = format!(
|
||||
"{DONE} {} done {} running {} waiting {FAILED} {} failed",
|
||||
tally.done, tally.running, tally.waiting, tally.failed
|
||||
);
|
||||
let switch_legend = if root_switched {
|
||||
format!(" {ROOT_SWITCH_MARK} root switch")
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
let legend = format!("{BEAD} running {WAITING_BEAD} waiting{switch_legend}");
|
||||
let gap = usize::from(width).saturating_sub(counts.chars().count() + legend.chars().count());
|
||||
let counts_style = if tally.failed > 0 {
|
||||
Style::new().red().bold()
|
||||
} else {
|
||||
Style::new()
|
||||
};
|
||||
let line = if gap >= 2 {
|
||||
Line::from(vec![
|
||||
Span::styled(counts, counts_style),
|
||||
Span::raw(" ".repeat(gap)),
|
||||
Span::from(legend).dark_gray(),
|
||||
])
|
||||
} else {
|
||||
Line::from(Span::styled(counts, counts_style))
|
||||
};
|
||||
Paragraph::new(line).block(
|
||||
Block::new()
|
||||
.borders(Borders::TOP)
|
||||
.border_style(Style::new().dark_gray()),
|
||||
)
|
||||
struct TimelineEntry<'a> {
|
||||
label: Line<'a>,
|
||||
segments: Vec<Segment>,
|
||||
still_going_at: Option<Duration>,
|
||||
}
|
||||
|
||||
struct Segment {
|
||||
@@ -361,35 +539,6 @@ struct Segment {
|
||||
style: Style,
|
||||
}
|
||||
|
||||
fn milestone_segments(row: &MilestoneRow) -> Vec<Segment> {
|
||||
row.reached_at
|
||||
.map(|reached_at| Segment {
|
||||
from: row.started_at,
|
||||
to: reached_at,
|
||||
symbol: BEAD,
|
||||
style: Style::new().green(),
|
||||
})
|
||||
.into_iter()
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn unit_segments(row: &PendingRow, now: Duration) -> Vec<Segment> {
|
||||
let waiting_until = row.running_since.unwrap_or(now);
|
||||
let waiting = (waiting_until > row.queued_at).then(|| Segment {
|
||||
from: row.queued_at,
|
||||
to: waiting_until,
|
||||
symbol: WAITING_BEAD,
|
||||
style: Style::new().dark_gray(),
|
||||
});
|
||||
let running = row.running_since.map(|since| Segment {
|
||||
from: since,
|
||||
to: now,
|
||||
symbol: BEAD,
|
||||
style: Style::new().yellow(),
|
||||
});
|
||||
waiting.into_iter().chain(running).collect()
|
||||
}
|
||||
|
||||
struct Stroke {
|
||||
column: u16,
|
||||
glyphs: String,
|
||||
@@ -484,50 +633,38 @@ impl TimeAxis {
|
||||
.take_while(|offset| *offset <= self.span)
|
||||
}
|
||||
|
||||
fn root_switch_strokes(&self, root_switches: &[Duration]) -> Vec<Stroke> {
|
||||
root_switches
|
||||
.iter()
|
||||
.map(|at| {
|
||||
Stroke::run(
|
||||
self.column(*at),
|
||||
1,
|
||||
ROOT_SWITCH_MARK,
|
||||
Style::new().dark_gray(),
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn labels(&self) -> Line<'static> {
|
||||
fn labels(&self, style: Style) -> Line<'static> {
|
||||
canvas_line(
|
||||
self.width,
|
||||
self.tick_offsets().map(|offset| {
|
||||
let glyphs = AXIS_LABEL.unsigned_duration_to_string(&offset);
|
||||
let glyphs = if offset.is_zero() && self.origin.is_zero() {
|
||||
KERNEL_ORIGIN_LABEL.to_owned()
|
||||
} else {
|
||||
AXIS_LABEL.unsigned_duration_to_string(&offset)
|
||||
};
|
||||
let label_width = u16::try_from(glyphs.len()).unwrap_or(self.width);
|
||||
Stroke {
|
||||
column: self
|
||||
.column(self.origin + offset)
|
||||
.min(self.width.saturating_sub(label_width)),
|
||||
glyphs,
|
||||
style: Style::new().dark_gray(),
|
||||
style,
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
fn ticks_line(&self, root_switches: &[Duration]) -> Line<'static> {
|
||||
fn ticks_line(&self, root_switches: &[Duration], style: Style) -> Line<'static> {
|
||||
canvas_line(
|
||||
self.width,
|
||||
self.root_switch_strokes(root_switches)
|
||||
.into_iter()
|
||||
.chain(self.tick_offsets().map(|offset| {
|
||||
Stroke::run(
|
||||
self.column(self.origin + offset),
|
||||
1,
|
||||
'|',
|
||||
Style::new().dark_gray(),
|
||||
)
|
||||
})),
|
||||
root_switches
|
||||
.iter()
|
||||
.map(|at| Stroke::run(self.column(*at), 1, ROOT_SWITCH_MARK, style))
|
||||
.chain(
|
||||
self.tick_offsets().map(|offset| {
|
||||
Stroke::run(self.column(self.origin + offset), 1, '|', style)
|
||||
}),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -536,47 +673,19 @@ impl TimeAxis {
|
||||
segments: &[Segment],
|
||||
still_going_at: Option<Duration>,
|
||||
root_switches: &[Duration],
|
||||
switch_style: Style,
|
||||
) -> Line<'static> {
|
||||
let switches = root_switches
|
||||
.iter()
|
||||
.map(|at| Stroke::run(self.column(*at), 1, ROOT_SWITCH_MARK, switch_style));
|
||||
let bars = segments.iter().map(|segment| {
|
||||
let start = self.column(segment.from);
|
||||
let end = self.column(segment.to).max(start + 1);
|
||||
Stroke::run(start, end - start, segment.symbol, segment.style)
|
||||
});
|
||||
let still_going = still_going_at
|
||||
.map(|now| Stroke::run(self.column(now), 1, STILL_GOING, Style::new().dark_gray()));
|
||||
canvas_line(
|
||||
self.width,
|
||||
self.root_switch_strokes(root_switches)
|
||||
.into_iter()
|
||||
.chain(bars)
|
||||
.chain(still_going),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn status_marker(row: &PendingRow, frame: u64) -> Span<'static> {
|
||||
match (row.is_target, row.status) {
|
||||
(true, _) => Span::raw(""),
|
||||
(false, RowStatus::Running) => {
|
||||
let spinner = SPINNER[usize::try_from(frame % 4).unwrap_or_default()];
|
||||
Span::from(format!("[{spinner}] ")).yellow()
|
||||
}
|
||||
(false, RowStatus::Waiting) => Span::from("[ ] ").dark_gray(),
|
||||
}
|
||||
}
|
||||
|
||||
fn timeline_marker(row: &PendingRow) -> Span<'static> {
|
||||
match row.status {
|
||||
RowStatus::Running => Span::from(format!("{RUNNING_MARK} ")).yellow(),
|
||||
RowStatus::Waiting => Span::raw(" "),
|
||||
}
|
||||
}
|
||||
|
||||
fn label_style(row: &PendingRow) -> Style {
|
||||
match (row.is_target, row.status) {
|
||||
(true, _) => Style::new().cyan(),
|
||||
(false, RowStatus::Running) => Style::new(),
|
||||
(false, RowStatus::Waiting) => Style::new().dark_gray(),
|
||||
let still_going =
|
||||
still_going_at.map(|now| Stroke::run(self.column(now), 1, STILL_GOING, switch_style));
|
||||
canvas_line(self.width, switches.chain(bars).chain(still_going))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,6 +734,7 @@ mod tests {
|
||||
frame.render_widget(
|
||||
BootView {
|
||||
state,
|
||||
palette: &Palette::default(),
|
||||
now,
|
||||
host: "ryzen",
|
||||
frame: 1,
|
||||
@@ -663,7 +773,7 @@ mod tests {
|
||||
(
|
||||
facts(
|
||||
"multi-user.target",
|
||||
&["docker.service", "systemd-rfkill.service"],
|
||||
&["docker.service", "systemd-rfkill.service", "web.service"],
|
||||
),
|
||||
Activity::default(),
|
||||
),
|
||||
@@ -672,8 +782,10 @@ mod tests {
|
||||
facts("systemd-rfkill.service", &[]),
|
||||
running_since(6000 * MS),
|
||||
),
|
||||
(facts("web.service", &[]), Activity::default()),
|
||||
(facts("sysinit.target", &[]), Activity::default()),
|
||||
(facts("nvidia-powerd.service", &[]), Activity::default()),
|
||||
(facts("udev-settle.service", &[]), running_since(2000 * MS)),
|
||||
]
|
||||
.into_iter()
|
||||
.zip(1..)
|
||||
@@ -682,8 +794,9 @@ mod tests {
|
||||
state.track_unit(unit, activity);
|
||||
state.queue_job(id, &name, 1000 * MS);
|
||||
});
|
||||
state.finish_job(5, JobResult::Done, 4000 * MS);
|
||||
state.finish_job(6, JobResult::Failed, 5000 * MS);
|
||||
state.finish_job(6, JobResult::Done, 4000 * MS);
|
||||
state.finish_job(7, JobResult::Failed, 5000 * MS);
|
||||
state.finish_job(8, JobResult::Done, 3500 * MS);
|
||||
state
|
||||
}
|
||||
|
||||
@@ -691,41 +804,48 @@ mod tests {
|
||||
fn tree_on_top_timeline_below() {
|
||||
let lines = render(&boot_in_progress(), 12_400 * MS, 110, 24);
|
||||
let screen = lines.join("\n");
|
||||
assert!(lines[0].starts_with("boot-tree ryzen"), "{screen}");
|
||||
assert!(lines[0].ends_with("12.4s"), "{screen}");
|
||||
assert_eq!(lines[0], "boot-tree ryzen", "{screen}");
|
||||
assert!(lines[2].starts_with("── stage 2 ──"), "{screen}");
|
||||
assert!(lines[2].ends_with("12.4s ──"), "{screen}");
|
||||
assert!(lines[3].starts_with("graphical.target"), "{screen}");
|
||||
assert!(lines[4].starts_with("└─ multi-user.target"), "{screen}");
|
||||
assert!(lines[5].starts_with(" ├─ [/] systemd-rfkill"), "{screen}");
|
||||
assert!(lines[6].starts_with(" └─ [/] docker"), "{screen}");
|
||||
assert!(lines[6].starts_with(" ├─ [/] docker"), "{screen}");
|
||||
assert!(lines[7].starts_with(" └─ [ ] web"), "{screen}");
|
||||
assert!(
|
||||
lines[7].starts_with("× nvidia-powerd.service failed"),
|
||||
lines[8].starts_with("× nvidia-powerd.service failed"),
|
||||
"{screen}"
|
||||
);
|
||||
let timeline = lines
|
||||
.iter()
|
||||
.position(|line| line.contains(" timeline "))
|
||||
.expect("timeline panel");
|
||||
assert_eq!(timeline, 24 - 2 - 3 - 3, "{screen}");
|
||||
assert!(lines[timeline + 1].contains("0s"), "{screen}");
|
||||
assert!(
|
||||
lines[timeline + 3].starts_with("√ sysinit.target (1 unit)"),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(lines[timeline + 3].contains('■'), "{screen}");
|
||||
assert!(
|
||||
lines[timeline + 4].starts_with("► systemd-rfkill"),
|
||||
lines[timeline + 1].starts_with(&format!("{:29}kernel", "")),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(
|
||||
lines[timeline + 4].contains("·■") && lines[timeline + 4].ends_with('▶'),
|
||||
lines[timeline + 3].starts_with("√ sysinit.target (2 units)"),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(lines[timeline + 4].starts_with("√ udev-settle"), "{screen}");
|
||||
assert!(lines[timeline + 4].contains('■'), "{screen}");
|
||||
assert!(
|
||||
lines[timeline + 5].starts_with("► systemd-rfkill"),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(
|
||||
lines[timeline + 5].contains("·■") && lines[timeline + 5].ends_with('▶'),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(lines[timeline + 6].starts_with("► docker"), "{screen}");
|
||||
assert!(
|
||||
lines[timeline..].iter().all(|line| !line.contains(" web")),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(lines[timeline + 5].starts_with("► docker"), "{screen}");
|
||||
assert!(!screen.contains("root switch"), "{screen}");
|
||||
assert!(
|
||||
lines[23].starts_with("√ 1 done 2 running 2 waiting × 1 failed"),
|
||||
lines[23].starts_with("√ 2 done 2 running 3 waiting × 1 failed"),
|
||||
"{screen}"
|
||||
);
|
||||
}
|
||||
@@ -754,6 +874,7 @@ mod tests {
|
||||
state.queue_job(2, "graphical.target", 7300 * MS);
|
||||
let lines = render(&state, 17_300 * MS, 110, 24);
|
||||
let screen = lines.join("\n");
|
||||
assert!(lines[0].ends_with("17.3s"), "{screen}");
|
||||
assert!(
|
||||
lines[2].starts_with("── initrd ── ■ done in 7.2s · 1 unit ──"),
|
||||
"{screen}"
|
||||
@@ -776,10 +897,26 @@ mod tests {
|
||||
Some(switch_column),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(lines[timeline + 3].contains("■│"), "{screen}");
|
||||
assert!(screen.contains("│ root switch"), "{screen}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completion_announces_the_handover() {
|
||||
let mut state = BootState::new(Phase::Host);
|
||||
state.set_root("graphical.target".to_owned());
|
||||
state.track_unit(facts("graphical.target", &[]), Activity::default());
|
||||
state.queue_job(1, "graphical.target", Duration::ZERO);
|
||||
state.finish_job(1, JobResult::Done, 9000 * MS);
|
||||
let lines = render(&state, 9500 * MS, 110, 24);
|
||||
assert!(
|
||||
lines[2].starts_with(
|
||||
"── ■ boot finished in 9.5s · handing over to display-manager.service ──"
|
||||
),
|
||||
"{}",
|
||||
lines.join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overflowing_trees_are_cut_with_a_count() {
|
||||
let mut state = BootState::new(Phase::Host);
|
||||
|
||||
Reference in new issue
Block a user