1pub mod capture;
7pub mod config;
8pub mod display;
9pub mod firmware;
10pub mod flash;
11pub mod ingest;
12pub mod model;
13pub mod params;
14pub mod probe;
15pub mod provision;
16pub mod restore;
17pub mod screen;
18pub mod upgrade;
19pub mod util;
20
21pub use colorlight as protocol;
22pub use panelspec;
23pub use panelspec::{read_library, Loader};
24pub use rcvbp;
25pub use receivers;
26
27use receivers::CardModel;
28
29use anyhow::{Context, Result};
30use std::io::{IsTerminal, Write};
31
32#[derive(Clone, Debug)]
34pub struct Ctx {
35 pub iface: String,
37 pub width: u16,
39 pub height: u16,
40 pub order: protocol::ColorOrder,
42 pub brightness: u8,
44 pub model: Option<&'static CardModel>,
47}
48
49impl Ctx {
50 pub fn model(&self) -> Result<&'static CardModel> {
55 self.model
56 .context("no card model: no card discovered and none named (--card NAME)")
57 }
58}
59
60pub trait Progress {
63 fn out(&mut self, line: &str);
64 fn err(&mut self, line: &str);
65 fn transient(&mut self, line: &str) {
68 self.err(line);
69 }
70 fn clear_transient(&mut self) {}
72 fn cancelled(&self) -> bool {
74 false
75 }
76}
77
78pub struct Stdio;
81
82impl Progress for Stdio {
83 fn out(&mut self, line: &str) {
84 println!("{line}");
85 }
86
87 fn err(&mut self, line: &str) {
88 eprintln!("{line}");
89 }
90
91 fn transient(&mut self, line: &str) {
92 let mut stderr = std::io::stderr();
93 if stderr.is_terminal() {
94 let _ = write!(stderr, "\r{line}");
95 }
96 }
97
98 fn clear_transient(&mut self) {
99 let mut stderr = std::io::stderr();
100 if stderr.is_terminal() {
101 let _ = write!(stderr, "\r");
102 }
103 }
104}
105
106pub fn check(p: &dyn Progress) -> Result<()> {
111 anyhow::ensure!(!p.cancelled(), "cancelled");
112 Ok(())
113}
114