From a7a67d7d8480bc774fe0dcc5b35da6aa768fad53 Mon Sep 17 00:00:00 2001 From: Breadway Date: Sun, 16 Aug 2026 00:26:07 +0800 Subject: [PATCH] Adopt bread_utils::screenshot_cli for --screenshot flags Replace the local settle delay, canvas defaults, and pair-validation error path with bread-utils v0.7.2. Hand-rolled argv parsing stays. --- src/cli.rs | 40 ++++++++++++++++++++++++++++++---------- src/screenshot.rs | 8 ++------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 654d2c2..62df4bc 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -4,7 +4,10 @@ //! `connect_command_line`, so `--onboard` on a second launch re-triggers the //! tour in the existing window instead of spawning a duplicate. -#[derive(Clone, Default)] +use bread_utils::screenshot_cli::{validate_pair, DEFAULT_HEIGHT, DEFAULT_WIDTH}; +use std::path::Path; + +#[derive(Clone)] pub struct Action { /// Force-restart the onboarding tour from step 0, regardless of whether /// it was already completed or in progress. @@ -38,19 +41,36 @@ pub struct Action { pub height: u32, } +impl Default for Action { + fn default() -> Self { + Self { + force_onboard: false, + autostart: false, + suggest: None, + tour_event: None, + screenshot: None, + output: None, + width: DEFAULT_WIDTH, + height: DEFAULT_HEIGHT, + } + } +} + impl Action { - /// `None` for a normal run. Exits the process with an error if - /// `--screenshot` was given without `--output`, before any GTK setup + /// `None` for a normal run. Exits the process with an error if the + /// `--screenshot` / `--output` pair is incomplete, before any GTK setup /// happens. pub fn screenshot_request(&self) -> Option { - let view = self.screenshot.clone()?; - let Some(output) = self.output.clone() else { - eprintln!("breadhelp: --screenshot requires --output"); + if let Err(e) = validate_pair( + self.screenshot.as_deref(), + self.output.as_deref().map(Path::new), + ) { + eprintln!("breadhelp: {e}"); std::process::exit(1); - }; + } Some(crate::screenshot::ScreenshotRequest { - view, - output: output.into(), + view: self.screenshot.clone()?, + output: self.output.clone()?.into(), width: self.width, height: self.height, }) @@ -58,7 +78,7 @@ impl Action { } pub fn parse(args: &[std::ffi::OsString]) -> Action { - let mut action = Action { width: 1920, height: 1080, ..Action::default() }; + let mut action = Action::default(); let mut it = args.iter().skip(1); while let Some(arg) = it.next() { if arg == "--onboard" { diff --git a/src/screenshot.rs b/src/screenshot.rs index 95a79cf..dd5ea16 100644 --- a/src/screenshot.rs +++ b/src/screenshot.rs @@ -21,19 +21,15 @@ //! both render embedded *inside* the Learn/Home tabs respectively, so //! they're already covered by those tabs' own captures. +use bread_utils::screenshot_cli::SETTLE_DELAY; use gtk4::prelude::*; use std::path::PathBuf; use std::time::Duration; -/// Extra settle time after `map` for the first frame to actually paint -/// before grim runs — `map` fires once the surface exists, not once -/// anything has been drawn into it. -const SETTLE_DELAY: Duration = Duration::from_millis(300); - /// Delay before opening the wizard modal — same reasoning as every other /// app's PRE_POPUP_DELAY: the parent window's own layout needs a beat to /// settle first. -const PRE_POPUP_DELAY: Duration = Duration::from_millis(300); +const PRE_POPUP_DELAY: Duration = SETTLE_DELAY; const KNOWN_VIEWS: &[&str] = &["home", "learn", "ask", "troubleshoot-wizard"];