diff --git a/examples/boot.rs b/examples/boot.rs index d369e82..23a670c 100644 --- a/examples/boot.rs +++ b/examples/boot.rs @@ -2,7 +2,7 @@ use std::{io, time::Duration}; use bootvine::{ boot_model::Phase, - scripted_boot::{Scenario, Step, failing, play, step}, + demo_script::scripted_boot::{Scenario, Step, failing, play, step}, }; const INITRD: &[Step] = &[ diff --git a/examples/luks.rs b/examples/luks.rs index 5fb7056..74a50f2 100644 --- a/examples/luks.rs +++ b/examples/luks.rs @@ -2,7 +2,7 @@ use std::{io, time::Duration}; use bootvine::{ boot_model::Phase, - scripted_boot::{Scenario, Step, play, step, unlocking}, + demo_script::scripted_boot::{Scenario, Step, play, step, unlocking}, }; const ROOT_PARTITION: &str = diff --git a/examples/shutdown.rs b/examples/shutdown.rs index 57042f8..f1f00e5 100644 --- a/examples/shutdown.rs +++ b/examples/shutdown.rs @@ -2,7 +2,7 @@ use std::{io, time::Duration}; use bootvine::{ boot_model::Phase, - scripted_boot::{Scenario, Step, play, step, stopping}, + demo_script::scripted_boot::{Scenario, Step, play, step, stopping}, }; const SHUTDOWN: &[Step] = &[ diff --git a/src/boot_model.rs b/src/boot_model.rs index 9fc40a3..20c2a9f 100644 --- a/src/boot_model.rs +++ b/src/boot_model.rs @@ -1,3 +1,4 @@ +pub mod boot_origin; mod job_ingestion; mod reached_milestones; mod unit_facts; diff --git a/src/boot_origin.rs b/src/boot_model/boot_origin.rs similarity index 100% rename from src/boot_origin.rs rename to src/boot_model/boot_origin.rs diff --git a/src/boot_model/job_ingestion.rs b/src/boot_model/job_ingestion.rs index 4906ae5..e57abb3 100644 --- a/src/boot_model/job_ingestion.rs +++ b/src/boot_model/job_ingestion.rs @@ -258,7 +258,7 @@ mod tests { use super::*; use crate::{ boot_model::RowStatus, - boot_test_fixtures::{ + demo_script::boot_test_fixtures::{ MS, activating, facts, nested_boot_sample as sample, queue_unit, queued_boot, waiting, waiting_rows, }, diff --git a/src/boot_model/reached_milestones.rs b/src/boot_model/reached_milestones.rs index 39f5687..680445d 100644 --- a/src/boot_model/reached_milestones.rs +++ b/src/boot_model/reached_milestones.rs @@ -92,7 +92,9 @@ mod tests { use super::*; use crate::{ boot_model::{Activity, JobResult, Phase}, - boot_test_fixtures::{MS, nested_boot_sample, queued_boot, waiting, waiting_rows}, + demo_script::boot_test_fixtures::{ + MS, nested_boot_sample, queued_boot, waiting, waiting_rows, + }, }; #[test] diff --git a/src/boot_model/unit_facts.rs b/src/boot_model/unit_facts.rs index 2c0be91..68df69c 100644 --- a/src/boot_model/unit_facts.rs +++ b/src/boot_model/unit_facts.rs @@ -172,7 +172,7 @@ pub(super) fn summary(facts: &UnitFacts) -> String { #[cfg(test)] mod tests { use super::*; - use crate::boot_test_fixtures::{facts, waiting}; + use crate::demo_script::boot_test_fixtures::{facts, waiting}; #[test] fn kinds_with_a_tag_drop_their_suffix() { diff --git a/src/boot_model/waiting_tree.rs b/src/boot_model/waiting_tree.rs index 5a5c4b1..6479412 100644 --- a/src/boot_model/waiting_tree.rs +++ b/src/boot_model/waiting_tree.rs @@ -241,7 +241,7 @@ impl BootState { #[cfg(test)] mod tests { use super::*; - use crate::boot_test_fixtures::{ + use crate::demo_script::boot_test_fixtures::{ nested_boot_sample, queued_boot, tree_outline, waiting, waiting_rows, }; diff --git a/src/boot_view.rs b/src/boot_view.rs index f4ee3e9..f9b8c4b 100644 --- a/src/boot_view.rs +++ b/src/boot_view.rs @@ -32,11 +32,10 @@ use self::{ unit_tree::UnitTree, }; use crate::{ - boot_model::{BootState, RowStatus, TreeRow, UnitKind, flatten_forest}, - boot_origin::BootOrigin, - color_scheme::Colors, - config_file::Timing, - font_glyphs::Glyphs, + boot_model::{ + BootState, RowStatus, TreeRow, UnitKind, boot_origin::BootOrigin, flatten_forest, + }, + screen_settings::{color_scheme::Colors, config_file::Timing, font_glyphs::Glyphs}, }; const DURATION_WIDTH: u16 = 8; diff --git a/src/boot_view/panel_render_tests.rs b/src/boot_view/panel_render_tests.rs index fad2491..3c022ed 100644 --- a/src/boot_view/panel_render_tests.rs +++ b/src/boot_view/panel_render_tests.rs @@ -6,8 +6,8 @@ use super::{ }; use crate::{ boot_model::{BootState, JobResult, Phase}, - boot_test_fixtures::{MS, queue_unit, queued_boot, running, waiting}, - color_scheme::Colors, + demo_script::boot_test_fixtures::{MS, queue_unit, queued_boot, running, waiting}, + screen_settings::color_scheme::Colors, }; const CRYPTSETUP_MESSAGE: &str = diff --git a/src/boot_view/run_timeline.rs b/src/boot_view/run_timeline.rs index 97ad77b..058ff9d 100644 --- a/src/boot_view/run_timeline.rs +++ b/src/boot_view/run_timeline.rs @@ -16,8 +16,7 @@ use ratatui::{ use super::{fit_width, rule, unit_count}; use crate::{ boot_model::{FinishedRun, MilestoneRow}, - color_scheme::TimelineColors, - font_glyphs::Glyphs, + screen_settings::{color_scheme::TimelineColors, font_glyphs::Glyphs}, }; pub const LABEL_WIDTH: u16 = 28; diff --git a/src/boot_view/screen_chrome.rs b/src/boot_view/screen_chrome.rs index 270b408..a9bcfa5 100644 --- a/src/boot_view/screen_chrome.rs +++ b/src/boot_view/screen_chrome.rs @@ -10,10 +10,11 @@ use ratatui::{ use super::{DURATION_WIDTH, ELAPSED}; use crate::{ - boot_model::Tally, - boot_origin::BootOrigin, - color_scheme::{FooterColors, HeaderColors, PasswordColors}, - font_glyphs::Glyphs, + boot_model::{Tally, boot_origin::BootOrigin}, + screen_settings::{ + color_scheme::{FooterColors, HeaderColors, PasswordColors}, + font_glyphs::Glyphs, + }, }; pub const FOOTER_HEIGHT: u16 = 2; diff --git a/src/boot_view/screen_render_fixtures.rs b/src/boot_view/screen_render_fixtures.rs index 171f2ae..df46328 100644 --- a/src/boot_view/screen_render_fixtures.rs +++ b/src/boot_view/screen_render_fixtures.rs @@ -4,12 +4,9 @@ use ratatui::{Terminal, backend::TestBackend, buffer::Buffer}; use super::{BootView, PasswordPrompt}; use crate::{ - boot_model::{BootState, JobResult, Phase}, - boot_origin::BootOrigin, - boot_test_fixtures::{MS, queued_boot, running, waiting}, - color_scheme::Colors, - config_file::Timing, - font_glyphs::Glyphs, + boot_model::{BootState, JobResult, Phase, boot_origin::BootOrigin}, + demo_script::boot_test_fixtures::{MS, queued_boot, running, waiting}, + screen_settings::{color_scheme::Colors, config_file::Timing, font_glyphs::Glyphs}, }; pub fn render(state: &BootState, now: Duration, width: u16, height: u16) -> Vec { diff --git a/src/boot_view/stage_summary.rs b/src/boot_view/stage_summary.rs index 89bc5fc..10336dc 100644 --- a/src/boot_view/stage_summary.rs +++ b/src/boot_view/stage_summary.rs @@ -9,7 +9,10 @@ use ratatui::{ }; use super::{BRANCH, ELAPSED, LAST_BRANCH, unit_count}; -use crate::{boot_model::BootState, color_scheme::StageColors, font_glyphs::Glyphs}; +use crate::{ + boot_model::BootState, + screen_settings::{color_scheme::StageColors, font_glyphs::Glyphs}, +}; const SHUTDOWN_SUCCESSOR: &str = "systemd-shutdown"; const PHASE_WIDTH: usize = 9; diff --git a/src/boot_view/tree_height_fitting.rs b/src/boot_view/tree_height_fitting.rs index 54153ab..296a2f3 100644 --- a/src/boot_view/tree_height_fitting.rs +++ b/src/boot_view/tree_height_fitting.rs @@ -94,7 +94,7 @@ mod tests { use super::*; use crate::{ boot_model::{BootState, Phase}, - boot_test_fixtures::{ + demo_script::boot_test_fixtures::{ activating, nested_boot_sample, queued_boot, running, tree_outline, waiting, }, }; diff --git a/src/boot_view/tree_render_tests.rs b/src/boot_view/tree_render_tests.rs index 9f655da..a3e5a42 100644 --- a/src/boot_view/tree_render_tests.rs +++ b/src/boot_view/tree_render_tests.rs @@ -5,7 +5,7 @@ use unicode_width::UnicodeWidthStr; use super::screen_render_fixtures::{boot_in_progress, chain_boot, described_boot, render}; use crate::{ boot_model::{JobResult, Phase}, - boot_test_fixtures::{MS, queue_unit, queued_boot, running, waiting}, + demo_script::boot_test_fixtures::{MS, queue_unit, queued_boot, running, waiting}, }; #[test] diff --git a/src/boot_view/unit_tree.rs b/src/boot_view/unit_tree.rs index df82d4a..41b7d8f 100644 --- a/src/boot_view/unit_tree.rs +++ b/src/boot_view/unit_tree.rs @@ -12,8 +12,7 @@ use unicode_width::UnicodeWidthStr; use super::{BRANCH, DURATION_WIDTH, ELAPSED, ENDED_TRUNK, LAST_BRANCH, PASSING_TRUNK, fit_width}; use crate::{ boot_model::{RowStatus, TreeRow, UnitKind}, - color_scheme::TreeColors, - font_glyphs::Glyphs, + screen_settings::{color_scheme::TreeColors, font_glyphs::Glyphs}, }; const SPINNER: [char; 4] = ['|', '/', '-', '\\']; diff --git a/src/console_session.rs b/src/console_session.rs new file mode 100644 index 0000000..faf49de --- /dev/null +++ b/src/console_session.rs @@ -0,0 +1,4 @@ +pub mod ask_password; +pub mod console_takeover; +pub mod passphrase_input; +pub mod watch_loop; diff --git a/src/ask_password.rs b/src/console_session/ask_password.rs similarity index 97% rename from src/ask_password.rs rename to src/console_session/ask_password.rs index da6e47c..98c3cfd 100644 --- a/src/ask_password.rs +++ b/src/console_session/ask_password.rs @@ -8,7 +8,6 @@ use std::{ time::Duration, }; -use bootvine::{boot_view::PasswordPrompt, passphrase_input}; use crossterm::event::Event; use rustix::{ fs::inotify::{self, CreateFlags, WatchFlags}, @@ -17,7 +16,10 @@ use rustix::{ }; use zeroize::Zeroizing; -use crate::monotonic_clock::monotonic_now; +use crate::{ + boot_view::PasswordPrompt, console_session::passphrase_input, + systemd_link::monotonic_clock::monotonic_now, +}; const REQUESTS: &str = "/run/systemd/ask-password"; const REQUEST_PREFIX: &str = "ask."; @@ -29,6 +31,7 @@ pub struct RequestWatch { } impl RequestWatch { + #[must_use] pub fn open() -> Option { fs::create_dir_all(REQUESTS).ok()?; let inotify = inotify::init(CreateFlags::CLOEXEC | CreateFlags::NONBLOCK).ok()?; @@ -45,6 +48,7 @@ impl RequestWatch { Some(Self { inotify }) } + #[must_use] pub fn changed(&self) -> bool { let mut events = [0_u8; INOTIFY_BUFFER]; iter::from_fn(|| { @@ -74,6 +78,7 @@ pub struct PasswordRequest { asker: Option, } +#[must_use] pub fn requested() -> bool { !request_files().is_empty() } @@ -195,6 +200,7 @@ impl PasswordEntry { self.request.is_awaited() && (!requests_changed || self.request.file.exists()) } + #[must_use] pub fn prompt(&self) -> PasswordPrompt<'_> { let input = if self.request.silent { String::new() diff --git a/src/console_takeover.rs b/src/console_session/console_takeover.rs similarity index 98% rename from src/console_takeover.rs rename to src/console_session/console_takeover.rs index 3feca4a..ae0cebf 100644 --- a/src/console_takeover.rs +++ b/src/console_session/console_takeover.rs @@ -1,6 +1,5 @@ use std::{collections::HashSet, fs, ptr}; -use bootvine::font_glyphs::Glyphs; use rustix::{ io::Errno, ioctl::{Getter, IntegerSetter, Opcode, Updater, ioctl}, @@ -8,7 +7,7 @@ use rustix::{ termios::ttyname, }; -use crate::ask_password; +use crate::{console_session::ask_password, screen_settings::font_glyphs::Glyphs}; const GIO_UNIMAP: Opcode = 0x4B66; const VT_GETSTATE: Opcode = 0x5603; @@ -43,6 +42,7 @@ impl Console { } } + #[must_use] pub fn answers_password_prompts(&self) -> bool { self.for_system && self.foreground.is_some() } diff --git a/src/passphrase_input.rs b/src/console_session/passphrase_input.rs similarity index 100% rename from src/passphrase_input.rs rename to src/console_session/passphrase_input.rs diff --git a/src/watch_loop.rs b/src/console_session/watch_loop.rs similarity index 92% rename from src/watch_loop.rs rename to src/console_session/watch_loop.rs index c52dabd..7f5d4d2 100644 --- a/src/watch_loop.rs +++ b/src/console_session/watch_loop.rs @@ -10,14 +10,6 @@ use std::{ time::{Duration, Instant}, }; -use bootvine::{ - boot_model::{BootState, Phase}, - boot_origin::BootOrigin, - boot_view::BootView, - color_scheme::Colors, - config_file::Timing, - passphrase_input::asks_to_quit, -}; use crossterm::event; use ratatui::{ DefaultTerminal, @@ -34,13 +26,21 @@ use rustix::{ use signal_hook::{consts::SIGTERM, flag}; use crate::{ - ask_password::{PasswordEntry, RequestWatch}, - boot_feed::{Feed, RootRequest}, - console_takeover::Console, - monotonic_clock::monotonic_now, - switch_root::INITRD_RELEASE, - systemd_bus::{Scope, Session}, - watch_error::Error, + boot_model::{BootState, Phase, boot_origin::BootOrigin}, + boot_view::BootView, + console_session::{ + ask_password::{PasswordEntry, RequestWatch}, + console_takeover::Console, + passphrase_input::asks_to_quit, + }, + screen_settings::{color_scheme::Colors, config_file::Timing}, + systemd_link::{ + boot_feed::{Feed, RootRequest}, + link_error::Error, + monotonic_clock::monotonic_now, + switch_root::INITRD_RELEASE, + systemd_bus::{Scope, Session}, + }, }; const FRAME_INTERVAL: Duration = Duration::from_millis(100); diff --git a/src/demo_script.rs b/src/demo_script.rs new file mode 100644 index 0000000..c185991 --- /dev/null +++ b/src/demo_script.rs @@ -0,0 +1,3 @@ +#[cfg(test)] +pub(crate) mod boot_test_fixtures; +pub mod scripted_boot; diff --git a/src/boot_test_fixtures.rs b/src/demo_script/boot_test_fixtures.rs similarity index 100% rename from src/boot_test_fixtures.rs rename to src/demo_script/boot_test_fixtures.rs diff --git a/src/scripted_boot.rs b/src/demo_script/scripted_boot.rs similarity index 97% rename from src/scripted_boot.rs rename to src/demo_script/scripted_boot.rs index 6c9c002..e77bb73 100644 --- a/src/scripted_boot.rs +++ b/src/demo_script/scripted_boot.rs @@ -10,13 +10,13 @@ use ratatui::{ }; use crate::{ - boot_model::{ActiveState, Activity, BootState, JobKind, JobResult, Phase, UnitFacts}, - boot_origin::BootOrigin, + boot_model::{ + ActiveState, Activity, BootState, JobKind, JobResult, Phase, UnitFacts, + boot_origin::BootOrigin, + }, boot_view::{BootView, PasswordPrompt}, - color_scheme::Colors, - config_file::Timing, - font_glyphs::Glyphs, - passphrase_input, + console_session::passphrase_input, + screen_settings::{color_scheme::Colors, config_file::Timing, font_glyphs::Glyphs}, }; const FRAME_INTERVAL: Duration = Duration::from_millis(100); diff --git a/src/lib.rs b/src/lib.rs index 3298a2c..287af3d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,6 @@ pub mod boot_model; -pub mod boot_origin; -#[cfg(test)] -mod boot_test_fixtures; pub mod boot_view; -pub mod color_scheme; -pub mod config_file; -pub mod font_glyphs; -pub mod passphrase_input; -pub mod scripted_boot; +pub mod console_session; +pub mod demo_script; +pub mod screen_settings; +pub mod systemd_link; diff --git a/src/main.rs b/src/main.rs index 238c7f6..f997c4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,3 @@ -mod ask_password; -mod boot_feed; -mod console_takeover; -mod monotonic_clock; -mod switch_root; -mod systemd_bus; -mod watch_error; -mod watch_loop; - use std::{ error::Error, io::ErrorKind, @@ -15,16 +6,16 @@ use std::{ time::Duration, }; -use bootvine::config_file::{Config, ConfigError, Timing, default_config_table, read_config_file}; +use bootvine::{ + console_session::watch_loop::{Settings, run}, + screen_settings::config_file::{ + Config, ConfigError, Timing, default_config_table, read_config_file, + }, + systemd_link::{boot_feed::RootRequest, systemd_bus::Scope}, +}; use clap::{Parser, Subcommand, ValueEnum}; use jiff::fmt::friendly::SpanParser; -use crate::{ - boot_feed::RootRequest, - systemd_bus::Scope, - watch_loop::{Settings, run}, -}; - #[derive(Parser)] #[command( about = "Live dependency tree of systemd jobs while the system boots", diff --git a/src/screen_settings.rs b/src/screen_settings.rs new file mode 100644 index 0000000..9e194a8 --- /dev/null +++ b/src/screen_settings.rs @@ -0,0 +1,3 @@ +pub mod color_scheme; +pub mod config_file; +pub mod font_glyphs; diff --git a/src/color_scheme.rs b/src/screen_settings/color_scheme.rs similarity index 100% rename from src/color_scheme.rs rename to src/screen_settings/color_scheme.rs diff --git a/src/config_file.rs b/src/screen_settings/config_file.rs similarity index 98% rename from src/config_file.rs rename to src/screen_settings/config_file.rs index 2616087..0225182 100644 --- a/src/config_file.rs +++ b/src/screen_settings/config_file.rs @@ -5,7 +5,7 @@ use jiff::fmt::serde::unsigned_duration::friendly::compact::required as friendly use serde::{Deserialize, Serialize}; use toml::{Table, Value, de::Error as ParseError, ser::Error as SerializeError}; -use crate::color_scheme::Colors; +use crate::screen_settings::color_scheme::Colors; #[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)] #[serde(default, deny_unknown_fields, rename_all = "kebab-case")] diff --git a/src/font_glyphs.rs b/src/screen_settings/font_glyphs.rs similarity index 100% rename from src/font_glyphs.rs rename to src/screen_settings/font_glyphs.rs diff --git a/src/systemd_link.rs b/src/systemd_link.rs new file mode 100644 index 0000000..dc87d22 --- /dev/null +++ b/src/systemd_link.rs @@ -0,0 +1,5 @@ +pub mod boot_feed; +pub mod link_error; +pub mod monotonic_clock; +pub mod switch_root; +pub mod systemd_bus; diff --git a/src/boot_feed.rs b/src/systemd_link/boot_feed.rs similarity index 96% rename from src/boot_feed.rs rename to src/systemd_link/boot_feed.rs index f46ae5e..b1d2cb4 100644 --- a/src/boot_feed.rs +++ b/src/systemd_link/boot_feed.rs @@ -6,14 +6,16 @@ use std::{ time::{Duration, Instant}, }; -use bootvine::boot_model::{BootState, HANDOFF_UNIT, JobKind, Phase}; use dbus::Path; use crate::{ - monotonic_clock::monotonic_now, - switch_root::Sysroot, - systemd_bus::{Scope, Session, Signal}, - watch_error::Error, + boot_model::{BootState, HANDOFF_UNIT, JobKind, Phase}, + systemd_link::{ + link_error::Error, + monotonic_clock::monotonic_now, + switch_root::Sysroot, + systemd_bus::{Scope, Session, Signal}, + }, }; const RECONNECT_PATIENCE: Duration = Duration::from_secs(60); @@ -65,6 +67,7 @@ pub struct Feed { } impl Feed { + #[must_use] pub fn new(phase: Phase, scope: Scope, target: RootRequest) -> Self { Self { connections: 0, @@ -81,6 +84,7 @@ impl Feed { } } + #[must_use] pub fn session_fd(&self) -> Option> { match &self.link { Link::Connected(session) => Some(session.as_fd()), diff --git a/src/watch_error.rs b/src/systemd_link/link_error.rs similarity index 100% rename from src/watch_error.rs rename to src/systemd_link/link_error.rs diff --git a/src/monotonic_clock.rs b/src/systemd_link/monotonic_clock.rs similarity index 95% rename from src/monotonic_clock.rs rename to src/systemd_link/monotonic_clock.rs index d8e8df8..58bfe89 100644 --- a/src/monotonic_clock.rs +++ b/src/systemd_link/monotonic_clock.rs @@ -2,6 +2,7 @@ use std::time::Duration; use rustix::time::{ClockId, clock_gettime}; +#[must_use] pub fn monotonic_now() -> Duration { let now = clock_gettime(ClockId::Monotonic); Duration::new( diff --git a/src/switch_root.rs b/src/systemd_link/switch_root.rs similarity index 100% rename from src/switch_root.rs rename to src/systemd_link/switch_root.rs diff --git a/src/systemd_bus.rs b/src/systemd_link/systemd_bus.rs similarity index 98% rename from src/systemd_bus.rs rename to src/systemd_link/systemd_bus.rs index bcd2674..d9210c6 100644 --- a/src/systemd_bus.rs +++ b/src/systemd_link/systemd_bus.rs @@ -4,14 +4,16 @@ use std::{ time::Duration, }; -use bootvine::boot_model::{ActiveState, Activity, JobKind, JobResult, UnitFacts}; use dbus::{ Message, MessageType, Path, arg::{AppendAll, PropMap, RefArg, Variant}, channel::{BusType, Channel}, }; -use crate::watch_error::Error; +use crate::{ + boot_model::{ActiveState, Activity, JobKind, JobResult, UnitFacts}, + systemd_link::link_error::Error, +}; const DESTINATION: &str = "org.freedesktop.systemd1"; const MANAGER_PATH: &str = "/org/freedesktop/systemd1";