feat: animate at 60 fps with timers in hundredths and bars that grow by eighths
Frames tick every 16 ms; password checks and the bus's fallback wake-ups keep their own 100 ms clock. Running units show hundredths, and a running bar's tip fills in eighths when the console font has the block glyphs. The scripted boot demo uses about 2% of a core.
This commit is contained in:
1 parent
a071b2d065
commit
0a29c7c88a
11 files changed
+93
-23
No files matched your search
+3
-1
@@ -41,7 +41,7 @@ use crate::{
|
||||
screen_settings::{color_scheme::Colors, config_file::Timing, font_glyphs::Glyphs},
|
||||
};
|
||||
|
||||
const DURATION_WIDTH: u16 = 8;
|
||||
const DURATION_WIDTH: u16 = 9;
|
||||
const MIN_BAR_WIDTH: u16 = 12;
|
||||
const MIN_HEIGHT_FOR_TIMELINE: u16 = 12;
|
||||
const MIN_TIMELINE_HEIGHT: u16 = run_timeline::CHROME_HEIGHT + 4;
|
||||
@@ -57,6 +57,8 @@ const ELAPSED: SpanPrinter = SpanPrinter::new()
|
||||
.fractional(Some(FractionalUnit::Second))
|
||||
.precision(Some(1));
|
||||
|
||||
const RUNNING_ELAPSED: SpanPrinter = ELAPSED.precision(Some(2));
|
||||
|
||||
pub struct BootView<'a> {
|
||||
pub state: &'a BootState,
|
||||
pub projection: &'a BootProjection,
|
||||
|
||||
@@ -54,7 +54,8 @@ fn tree_on_top_timeline_below() {
|
||||
"{screen}"
|
||||
);
|
||||
assert!(
|
||||
lines[timeline + 4].contains("·■") && lines[timeline + 4].ends_with('▶'),
|
||||
lines[timeline + 4].contains("·■")
|
||||
&& lines[timeline + 4].ends_with(['▏', '▎', '▍', '▌', '▋', '▊', '▉', '█']),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(lines[timeline + 5].starts_with("► docker"), "{screen}");
|
||||
|
||||
@@ -209,8 +209,19 @@ impl Widget for Timeline<'_> {
|
||||
));
|
||||
});
|
||||
if entry.still_going {
|
||||
ctx.marker(Marker::Custom(self.glyphs.still_going));
|
||||
ctx.draw(&Points::new(&[(self.now.as_secs_f64(), y)], axis_color));
|
||||
let tip = self
|
||||
.glyphs
|
||||
.growing_tip
|
||||
.map_or(self.glyphs.still_going, |tips| {
|
||||
tips[axis.eighths_into_column(self.now)]
|
||||
});
|
||||
let tip_color = if self.glyphs.growing_tip.is_some() {
|
||||
self.colors.running
|
||||
} else {
|
||||
axis_color
|
||||
};
|
||||
ctx.marker(Marker::Custom(tip));
|
||||
ctx.draw(&Points::new(&[(self.now.as_secs_f64(), y)], tip_color));
|
||||
}
|
||||
});
|
||||
ctx.marker(Marker::Custom(self.glyphs.root_switch_mark));
|
||||
@@ -274,6 +285,13 @@ impl TimeAxis {
|
||||
]
|
||||
}
|
||||
|
||||
fn eighths_into_column(&self, at: Duration) -> usize {
|
||||
let last_column = u128::from(self.width.saturating_sub(1).max(1));
|
||||
let span = self.span.as_nanos().max(1);
|
||||
let scaled = at.saturating_sub(self.origin).as_nanos() * last_column;
|
||||
usize::try_from(scaled % span * 8 / span).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn columns_to_seconds(&self, columns: usize) -> f64 {
|
||||
let last_column = self.width.saturating_sub(1).max(1);
|
||||
let columns = u16::try_from(columns).unwrap_or(last_column);
|
||||
@@ -294,3 +312,24 @@ impl TimeAxis {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_tip_fills_its_column_in_eighths() {
|
||||
let axis = TimeAxis {
|
||||
origin: Duration::ZERO,
|
||||
span: Duration::from_secs(10),
|
||||
step: Duration::from_secs(1),
|
||||
width: 11,
|
||||
};
|
||||
let eighths = |millis: u64| axis.eighths_into_column(Duration::from_millis(millis));
|
||||
assert_eq!(eighths(2000), 0);
|
||||
assert_eq!(eighths(2125), 1);
|
||||
assert_eq!(eighths(2500), 4);
|
||||
assert_eq!(eighths(2999), 7);
|
||||
assert_eq!(eighths(3000), 0);
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ fn only_running_units_carry_a_timer() {
|
||||
let lines = render(&boot_in_progress(), 12_400 * MS, 110, 24);
|
||||
let screen = lines.join("\n");
|
||||
assert!(lines[2].ends_with("multi-user.target"), "{screen}");
|
||||
assert!(lines[3].ends_with("6.4s"), "{screen}");
|
||||
assert!(lines[3].ends_with("6.40s"), "{screen}");
|
||||
assert!(lines[5].ends_with("web"), "{screen}");
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ fn chains_fold_when_short_and_shorten_to_their_ends_when_narrow() {
|
||||
"{}",
|
||||
short.join("\n")
|
||||
);
|
||||
let narrow = render(&chain_boot(), 5000 * MS, 45, 8);
|
||||
let narrow = render(&chain_boot(), 5000 * MS, 46, 8);
|
||||
assert!(
|
||||
narrow[3].starts_with(" └─ [ ] network-wait ─ … ─ dbus"),
|
||||
"{}",
|
||||
|
||||
@@ -9,7 +9,9 @@ use ratatui::{
|
||||
};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use super::{BRANCH, DURATION_WIDTH, ELAPSED, ENDED_TRUNK, LAST_BRANCH, PASSING_TRUNK, fit_width};
|
||||
use super::{
|
||||
BRANCH, DURATION_WIDTH, ENDED_TRUNK, LAST_BRANCH, PASSING_TRUNK, RUNNING_ELAPSED, fit_width,
|
||||
};
|
||||
use crate::{
|
||||
boot_model::{RowStatus, TreeRow, UnitKind},
|
||||
screen_settings::{color_scheme::TreeColors, font_glyphs::Glyphs},
|
||||
@@ -207,7 +209,7 @@ impl UnitTree<'_> {
|
||||
RowStatus::Running { since, .. }
|
||||
if self.now.saturating_sub(since) >= self.hide_runs_shorter_than =>
|
||||
{
|
||||
ELAPSED.unsigned_duration_to_string(&self.now.saturating_sub(since))
|
||||
RUNNING_ELAPSED.unsigned_duration_to_string(&self.now.saturating_sub(since))
|
||||
}
|
||||
_ => String::new(),
|
||||
};
|
||||
|
||||
@@ -10,7 +10,10 @@ use crate::{
|
||||
ask_password::{PasswordEntry, RequestWatch},
|
||||
console_takeover::Console,
|
||||
passphrase_input::asks_to_quit,
|
||||
stream_sources::{CarriedItem, periodic_inputs, readable_source, unfold_carrying},
|
||||
stream_sources::{
|
||||
BACKGROUND_CHECK_INTERVAL, CarriedItem, periodic_inputs, readable_source,
|
||||
unfold_carrying,
|
||||
},
|
||||
watch_screen::{ConsoleDesk, ScreenInput, WatchEnding},
|
||||
},
|
||||
screen_settings::font_glyphs::Glyphs,
|
||||
@@ -76,7 +79,6 @@ impl ConsoleDesk for LiveDesk {
|
||||
}
|
||||
|
||||
fn frame_passed(&mut self, _state: &mut BootState, _now: Duration) -> ControlFlow<WatchEnding> {
|
||||
self.follow_requests(!self.requests_watched);
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
@@ -84,6 +86,10 @@ impl ConsoleDesk for LiveDesk {
|
||||
self.follow_requests(true);
|
||||
}
|
||||
|
||||
fn check_prompts(&mut self) {
|
||||
self.follow_requests(!self.requests_watched);
|
||||
}
|
||||
|
||||
fn keep_console_up(&mut self) -> bool {
|
||||
self.console.keep_up()
|
||||
}
|
||||
@@ -97,6 +103,10 @@ impl ConsoleDesk for LiveDesk {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prompt_check_inputs() -> impl Stream<Item = ScreenInput> {
|
||||
periodic_inputs(BACKGROUND_CHECK_INTERVAL, || ScreenInput::PromptCheck)
|
||||
}
|
||||
|
||||
pub fn console_upkeep_inputs() -> impl Stream<Item = ScreenInput> {
|
||||
periodic_inputs(CONSOLE_UPKEEP_INTERVAL, || ScreenInput::ConsoleUpkeep)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ use tokio::{
|
||||
|
||||
use crate::console_session::watch_screen::ScreenInput;
|
||||
|
||||
pub const FRAME_INTERVAL: Duration = Duration::from_millis(100);
|
||||
pub const FRAME_INTERVAL: Duration = Duration::from_millis(16);
|
||||
pub const BACKGROUND_CHECK_INTERVAL: Duration = Duration::from_millis(100);
|
||||
|
||||
pub struct CarriedItem<Item, State> {
|
||||
pub item: Item,
|
||||
|
||||
@@ -10,6 +10,7 @@ use crate::{
|
||||
console_takeover::Console,
|
||||
live_desk::{
|
||||
LiveDesk, console_upkeep_inputs, full_repaint_inputs, password_request_inputs,
|
||||
prompt_check_inputs,
|
||||
},
|
||||
stream_sources::{frame_inputs, key_inputs, termination_inputs},
|
||||
watch_screen::{WatchEnding, WatchScreen, watch_until_ending},
|
||||
@@ -84,22 +85,21 @@ async fn watch_live_boot(settings: &Settings, phase: Phase) -> Result<(), Error>
|
||||
requests.is_some(),
|
||||
);
|
||||
let password_inputs = requests.map(password_request_inputs).transpose()?;
|
||||
let inputs = stream::select(
|
||||
let event_inputs = stream::select(
|
||||
stream::select(
|
||||
bus_inputs(phase, settings.scope, settings.target.clone()),
|
||||
key_inputs()?,
|
||||
),
|
||||
stream::select(
|
||||
stream::select(
|
||||
frame_inputs(),
|
||||
stream::select(console_upkeep_inputs(), full_repaint_inputs()),
|
||||
),
|
||||
stream::select(
|
||||
termination_inputs()?,
|
||||
stream::iter(password_inputs).flatten(),
|
||||
),
|
||||
termination_inputs()?,
|
||||
stream::iter(password_inputs).flatten(),
|
||||
),
|
||||
);
|
||||
let timer_inputs = stream::select(
|
||||
stream::select(frame_inputs(), prompt_check_inputs()),
|
||||
stream::select(console_upkeep_inputs(), full_repaint_inputs()),
|
||||
);
|
||||
let inputs = stream::select(event_inputs, timer_inputs);
|
||||
let mut screen = WatchScreen::new(
|
||||
BootState::new(phase),
|
||||
desk,
|
||||
|
||||
@@ -23,6 +23,7 @@ pub enum ScreenInput {
|
||||
Boot(Vec<BootChange>),
|
||||
Key(Event),
|
||||
Frame,
|
||||
PromptCheck,
|
||||
ConsoleUpkeep,
|
||||
FullRepaint,
|
||||
PasswordRequests,
|
||||
@@ -45,6 +46,8 @@ pub trait ConsoleDesk {
|
||||
|
||||
fn password_requests_changed(&mut self) {}
|
||||
|
||||
fn check_prompts(&mut self) {}
|
||||
|
||||
fn keep_console_up(&mut self) -> bool {
|
||||
false
|
||||
}
|
||||
@@ -106,6 +109,10 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
||||
ScreenInput::Boot(changes) => self.apply_boot_changes(changes),
|
||||
ScreenInput::Key(event) => self.desk.press_key(&event, now),
|
||||
ScreenInput::Frame => self.desk.frame_passed(&mut self.state, now),
|
||||
ScreenInput::PromptCheck => {
|
||||
self.desk.check_prompts();
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
ScreenInput::ConsoleUpkeep => {
|
||||
self.full_repaint_due |= self.desk.keep_console_up();
|
||||
ControlFlow::Continue(())
|
||||
|
||||
@@ -5,6 +5,7 @@ pub struct Glyphs {
|
||||
pub bead: char,
|
||||
pub waiting_bead: char,
|
||||
pub still_going: char,
|
||||
pub growing_tip: Option<[char; 8]>,
|
||||
pub running_mark: char,
|
||||
pub root_switch_mark: char,
|
||||
pub stage_current: char,
|
||||
@@ -18,6 +19,7 @@ const FAILED: [char; 2] = ['×', 'x'];
|
||||
const BEAD: [char; 2] = ['■', '#'];
|
||||
const WAITING_BEAD: [char; 2] = ['·', '.'];
|
||||
const STILL_GOING: [char; 2] = ['▶', '>'];
|
||||
const GROWING_TIP: [char; 8] = ['▏', '▎', '▍', '▌', '▋', '▊', '▉', '█'];
|
||||
const RUNNING_MARK: [char; 3] = ['►', '▶', '>'];
|
||||
const ROOT_SWITCH_MARK: [char; 2] = ['│', '|'];
|
||||
const STAGE_MARKS: [&str; 3] = ["◆◇", "●○", "*o"];
|
||||
@@ -53,6 +55,10 @@ impl Glyphs {
|
||||
bead: symbol(&BEAD),
|
||||
waiting_bead: symbol(&WAITING_BEAD),
|
||||
still_going: symbol(&STILL_GOING),
|
||||
growing_tip: GROWING_TIP
|
||||
.iter()
|
||||
.all(|eighth| covers(*eighth))
|
||||
.then_some(GROWING_TIP),
|
||||
running_mark: symbol(&RUNNING_MARK),
|
||||
root_switch_mark: symbol(&ROOT_SWITCH_MARK),
|
||||
stage_current: stage_marks[0],
|
||||
@@ -92,11 +98,13 @@ mod tests {
|
||||
assert_eq!(glyphs.ellipsis, "...");
|
||||
assert_eq!(glyphs.chain_link, "─");
|
||||
assert_eq!((glyphs.stage_current, glyphs.stage_upcoming), ('*', 'o'));
|
||||
assert_eq!(glyphs.growing_tip, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_unicode_keeps_every_preferred_glyph() {
|
||||
let glyphs = Glyphs::default();
|
||||
assert_eq!((glyphs.done, glyphs.running_mark), ('√', '►'));
|
||||
assert_eq!(glyphs.growing_tip, Some(GROWING_TIP));
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ use tokio::time::sleep;
|
||||
use crate::{
|
||||
boot_model::{BootChange, BootState, HANDOFF_UNIT, JobKind, Phase},
|
||||
console_session::{
|
||||
stream_sources::{CarriedItem, FRAME_INTERVAL, unfold_carrying},
|
||||
stream_sources::{BACKGROUND_CHECK_INTERVAL, CarriedItem, unfold_carrying},
|
||||
watch_screen::ScreenInput,
|
||||
},
|
||||
systemd_link::{
|
||||
@@ -136,7 +136,7 @@ impl BusFeed {
|
||||
vec![ScreenInput::Boot(watched.changes), ScreenInput::FullRepaint]
|
||||
}
|
||||
Err(_) if Instant::now() < deadline => {
|
||||
sleep(FRAME_INTERVAL).await;
|
||||
sleep(BACKGROUND_CHECK_INTERVAL).await;
|
||||
self.link = Link::Connecting { deadline };
|
||||
Vec::new()
|
||||
}
|
||||
@@ -145,7 +145,7 @@ impl BusFeed {
|
||||
}
|
||||
|
||||
async fn receive(&mut self, mut connection: BusConnection) -> Vec<ScreenInput> {
|
||||
let Ok(signals) = connection.receive_signals(FRAME_INTERVAL).await else {
|
||||
let Ok(signals) = connection.receive_signals(BACKGROUND_CHECK_INTERVAL).await else {
|
||||
return self.lose_connection();
|
||||
};
|
||||
let progress = stream::iter(signals)
|
||||
|
||||
Reference in new issue
Block a user