Skip to main content

rpi_cli/
brand.rs

1//! 启动标志:`docs/images/rpi-logo.jpg` 那枚齿轮 + rpi 的终端版本。
2//!
3//! 标志由 [`render`] 的静态表格给出(32 列 × 16 行半块字符,用主题默认前景色),
4//! 不做 3D 扫描、不做自转动画:欢迎页只需要一张确定、紧凑、和源图同构的图,
5//! 首屏行数也不该被装饰吃掉。
6
7pub(crate) mod render;
8
9use rpi_tui::Component;
10
11/// 终端窗口/标签标题里的紧凑标记。
12pub const MARK: &str = "@";
13
14/// 把标志压成一行终端窗口标题。
15pub fn window_title(status: &str) -> String {
16    if status.is_empty() {
17        format!("{MARK} rpi")
18    } else {
19        format!("{MARK} rpi {status}")
20    }
21}
22
23/// 启动标志。加到欢迎页 header 里。
24pub struct BrandLockup;
25
26impl BrandLockup {
27    pub fn new() -> Self {
28        Self
29    }
30}
31
32impl Default for BrandLockup {
33    fn default() -> Self {
34        Self::new()
35    }
36}
37
38impl Component for BrandLockup {
39    fn render(&self, _width: usize) -> Vec<String> {
40        render::lockup()
41    }
42
43    fn invalidate(&self) {
44        // Nothing is cached: the frame is a static table plus the theme colour.
45    }
46
47    fn as_any(&self) -> &dyn std::any::Any {
48        self
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55    use rpi_tui::ansi::{strip_ansi, visible_width};
56
57    #[test]
58    fn lockup_fits_the_welcome_header() {
59        let rows = BrandLockup::new().render(80);
60        assert_eq!(rows.len(), render::ROWS);
61        // 首屏预算:80×24 下欢迎页只剩 17 行给转录区(见 `render` 的模块文档)。
62        assert_eq!(rows.len(), 12);
63        assert!(rows.iter().all(|row| visible_width(row) == render::COLS));
64        assert!(strip_ansi(&rows[5]).contains('█'));
65    }
66
67    #[test]
68    fn title_keeps_the_logo_identity_and_status_last() {
69        assert_eq!(window_title(""), "@ rpi");
70        assert_eq!(window_title("⟳"), "@ rpi ⟳");
71        assert_eq!(window_title("↻"), "@ rpi ↻");
72        assert!(!window_title("⟳").contains('\n'));
73    }
74}