fix: arrow glyph
This commit is contained in:
1 parent
329307b27c
commit
5433f23513
7 files changed
+65
-21
No files matched your search
@@ -12,7 +12,9 @@ It needs systemd ≥ 246 as PID 1, libdbus and a virtual terminal (it draws on
|
||||
tty12). With a systemd initrd it starts about a second after the kernel and
|
||||
follows the boot through the switch to the real root; without one it starts in
|
||||
stage 2. While it runs it quiets the kernel console and systemd's status
|
||||
output, and restores both when it hands the console back.
|
||||
output, and restores both when it hands the console back. Kernel messages from
|
||||
before it starts still reach the screen; boot with `quiet`, or set
|
||||
`boot.consoleLogLevel = 3` on NixOS, to keep those to errors.
|
||||
|
||||
It also follows shutdowns and reboots: the units being stopped, nested under
|
||||
the units that have to stop first, until systemd hands over to
|
||||
|
||||
@@ -25,6 +25,8 @@ in
|
||||
networking.hostName = "bootvine-demo";
|
||||
system.stateVersion = "26.05";
|
||||
|
||||
boot.consoleLogLevel = lib.mkForce 3;
|
||||
|
||||
boot.initrd.systemd = {
|
||||
enable = true;
|
||||
services.demo-initrd-probe = {
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
machine.wait_for_text("stage 2")
|
||||
machine.screenshot("stage-2")
|
||||
quieted = machine.succeed("cut -f1 /proc/sys/kernel/printk").strip()
|
||||
assert quieted == "1", f"stage 2 sysctl reopened the kernel console: {quieted}"
|
||||
|
||||
machine.wait_for_unit("greetd.service")
|
||||
machine.wait_until_succeeds("systemctl show -p ActiveState --value bootvine | grep -qx inactive")
|
||||
|
||||
+46
-5
@@ -1,5 +1,6 @@
|
||||
use std::{collections::HashSet, fs, ptr};
|
||||
|
||||
use bootvine::glyphs::Glyphs;
|
||||
use rustix::{
|
||||
io::Errno,
|
||||
ioctl::{Getter, IntegerSetter, Opcode, Updater, ioctl},
|
||||
@@ -15,17 +16,57 @@ const VIRTUAL_TERMINAL_PREFIX: &str = "/dev/tty";
|
||||
const KERNEL_PRINTK: &str = "/proc/sys/kernel/printk";
|
||||
const ALERTS_ONLY: &str = "1";
|
||||
|
||||
pub struct QuietKernelConsole {
|
||||
pub struct Console {
|
||||
quiet_kernel: Option<QuietKernelConsole>,
|
||||
pub glyphs: Glyphs,
|
||||
}
|
||||
|
||||
impl Console {
|
||||
pub fn take(quiets_kernel: bool) -> Self {
|
||||
Self {
|
||||
quiet_kernel: quiets_kernel.then(QuietKernelConsole::take).flatten(),
|
||||
glyphs: font_glyphs(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn keep_up(&mut self) {
|
||||
if let Some(quiet_kernel) = &mut self.quiet_kernel {
|
||||
quiet_kernel.keep_quiet();
|
||||
}
|
||||
self.glyphs = font_glyphs();
|
||||
}
|
||||
}
|
||||
|
||||
struct QuietKernelConsole {
|
||||
previous_level: String,
|
||||
}
|
||||
|
||||
fn console_level() -> Option<String> {
|
||||
let levels = fs::read_to_string(KERNEL_PRINTK).ok()?;
|
||||
levels.split_whitespace().next().map(ToOwned::to_owned)
|
||||
}
|
||||
|
||||
impl QuietKernelConsole {
|
||||
pub fn take() -> Option<Self> {
|
||||
let levels = fs::read_to_string(KERNEL_PRINTK).ok()?;
|
||||
let previous_level = levels.split_whitespace().next()?.to_owned();
|
||||
fn take() -> Option<Self> {
|
||||
let previous_level = console_level()?;
|
||||
fs::write(KERNEL_PRINTK, ALERTS_ONLY).ok()?;
|
||||
Some(Self { previous_level })
|
||||
}
|
||||
|
||||
fn keep_quiet(&mut self) {
|
||||
let Some(level) = console_level() else {
|
||||
return;
|
||||
};
|
||||
if level != ALERTS_ONLY && fs::write(KERNEL_PRINTK, ALERTS_ONLY).is_ok() {
|
||||
self.previous_level = level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn font_glyphs() -> Glyphs {
|
||||
font_characters().map_or_else(Glyphs::default, |characters| {
|
||||
Glyphs::fitting(|symbol| symbol.is_ascii() || characters.contains(&symbol))
|
||||
})
|
||||
}
|
||||
|
||||
impl Drop for QuietKernelConsole {
|
||||
@@ -51,7 +92,7 @@ fn read_unicode_map(map: &mut UnicodeMap) -> Result<(), Errno> {
|
||||
unsafe { ioctl(stdin(), Updater::<GIO_UNIMAP, UnicodeMap>::new(map)) }
|
||||
}
|
||||
|
||||
pub fn font_characters() -> Option<HashSet<char>> {
|
||||
fn font_characters() -> Option<HashSet<char>> {
|
||||
let mut probe = UnicodeMap {
|
||||
count: 0,
|
||||
pairs: ptr::null_mut(),
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ const STILL_GOING: [char; 2] = ['▶', '>'];
|
||||
const RUNNING_MARK: [char; 3] = ['►', '▶', '>'];
|
||||
const ROOT_SWITCH_MARK: [char; 2] = ['│', '|'];
|
||||
const ELLIPSIS: [&str; 2] = ["…", "..."];
|
||||
const CHAIN_LINK: [&str; 2] = ["→", "->"];
|
||||
const CHAIN_LINK: [&str; 2] = ["─", "-"];
|
||||
|
||||
impl Default for Glyphs {
|
||||
fn default() -> Self {
|
||||
@@ -83,7 +83,7 @@ mod tests {
|
||||
assert_eq!(glyphs.done, '√');
|
||||
assert_eq!(glyphs.failed, 'x');
|
||||
assert_eq!(glyphs.ellipsis, "...");
|
||||
assert_eq!(glyphs.chain_link, "→");
|
||||
assert_eq!(glyphs.chain_link, "─");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+8
-11
@@ -9,7 +9,6 @@ use std::{
|
||||
};
|
||||
|
||||
use bootvine::{
|
||||
glyphs::Glyphs,
|
||||
model::{BootState, Phase},
|
||||
palette::Palette,
|
||||
view::BootView,
|
||||
@@ -25,7 +24,7 @@ use signal_hook::{consts::SIGTERM, flag};
|
||||
|
||||
use crate::{
|
||||
clock::monotonic_now,
|
||||
console::{ForegroundVt, QuietKernelConsole, font_characters},
|
||||
console::{Console, ForegroundVt},
|
||||
error::Error,
|
||||
feed::Feed,
|
||||
sysroot::INITRD_RELEASE,
|
||||
@@ -63,13 +62,8 @@ pub fn run(options: &Options) -> Result<(), Error> {
|
||||
};
|
||||
let mut state = BootState::new(phase);
|
||||
let mut feed = Feed::new(options.scope, options.target.clone());
|
||||
let _quiet_kernel = (options.scope == Scope::System)
|
||||
.then(QuietKernelConsole::take)
|
||||
.flatten();
|
||||
let mut console = Console::take(options.scope == Scope::System);
|
||||
let _foreground = ForegroundVt::take();
|
||||
let glyphs = font_characters().map_or_else(Glyphs::default, |characters| {
|
||||
Glyphs::fitting(|symbol| symbol.is_ascii() || characters.contains(&symbol))
|
||||
});
|
||||
let mut terminal = ratatui::try_init()?;
|
||||
let watched = watch(
|
||||
&mut state,
|
||||
@@ -77,7 +71,7 @@ pub fn run(options: &Options) -> Result<(), Error> {
|
||||
&mut terminal,
|
||||
&terminate,
|
||||
&options.palette,
|
||||
&glyphs,
|
||||
&mut console,
|
||||
options.hold,
|
||||
);
|
||||
ratatui::restore();
|
||||
@@ -116,7 +110,7 @@ fn watch(
|
||||
terminal: &mut DefaultTerminal,
|
||||
terminate: &AtomicBool,
|
||||
palette: &Palette,
|
||||
glyphs: &Glyphs,
|
||||
console: &mut Console,
|
||||
hold: Duration,
|
||||
) -> Result<(), Error> {
|
||||
let host = uname().nodename().to_string_lossy().into_owned();
|
||||
@@ -127,12 +121,15 @@ fn watch(
|
||||
feed.pump(state, FRAME_INTERVAL)?;
|
||||
let repaint_due = feed.connections != painted_connections
|
||||
|| last_full_repaint.elapsed() >= FULL_REPAINT_INTERVAL;
|
||||
if repaint_due {
|
||||
console.keep_up();
|
||||
}
|
||||
let completed = terminal.draw(|canvas| {
|
||||
canvas.render_widget(
|
||||
BootView {
|
||||
state,
|
||||
palette,
|
||||
glyphs,
|
||||
glyphs: &console.glyphs,
|
||||
now: monotonic_now(),
|
||||
host: &host,
|
||||
frame,
|
||||
|
||||
+2
-2
@@ -396,7 +396,7 @@ mod tests {
|
||||
let wide = render(&state, 5000 * MS, 110, 24);
|
||||
assert!(
|
||||
wide[4].starts_with(
|
||||
"└─ [ ] systemd-poweroff → final.target → shutdown.target → local-fs.target → \
|
||||
"└─ [ ] systemd-poweroff ─ final.target ─ shutdown.target ─ local-fs.target ─ \
|
||||
demo-disk"
|
||||
),
|
||||
"{}",
|
||||
@@ -409,7 +409,7 @@ mod tests {
|
||||
);
|
||||
let narrow = render(&state, 5000 * MS, 60, 24);
|
||||
assert!(
|
||||
narrow[4].starts_with("└─ [ ] systemd-poweroff → … → demo-disk"),
|
||||
narrow[4].starts_with("└─ [ ] systemd-poweroff ─ … ─ demo-disk"),
|
||||
"{}",
|
||||
narrow.join("\n")
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user