1use rpi_tui::{ansi::visible_width, theme as current_theme, Component};
12
13pub const MARK: &str = "@";
16
17const LOGO_ROWS: [&str; 32] = [
18 " ",
19 " ",
20 " ",
21 " +%###%* ",
22 " .-+*: .@= -@. :**-. ",
23 " -*#+:-%*=*###. .###*=+%=:+##- ",
24 " -@: .=-:. .:-=. :@= ",
25 " .#%. .:=*#%%%%%%%#*=:. .##. ",
26 " .+=:.-#*: .-*%#+-:. ..-+#%*-. :*%-.:-+: ",
27 " :%+=+*#- .=%#-. .-#%+. :##+=+@: ",
28 " :@= -%#: :#@- =@: ",
29 " :*%=. =@= =@+. .=%*: ",
30 " .@* =@= -#-----*- -@+ +@: ",
31 " =@: :@* .=#%*+++*%#=. +@- .@= ",
32 " :+*##+ *@. :%%-..-=-: :#%: .@* +##*+- ",
33 " *%.. %% #%..+@*=*@*..#%. *% ..#*. ",
34 " *% .%% .#= :@+ =@: +@: *@ #*. ",
35 " -###*= *@. ....::. :@@*+*@*..#%. -*- .%# =*###= ",
36 " =@. :@+ .+@%#*#+ :@+---..-%%: :+: =@- .@+ ",
37 " .%* +@-.+@= :@= :+*%#=. -@- :@* +@. ",
38 " .-#*- +@=+@: :@= -@=. -@--@*. :*%=. ",
39 " :@+ -%@@: :@= -@- -@%@- =@: ",
40 " :%+:=+*- .=%::. :@= -@- ..-%=. :*+=:+@- ",
41 " .**=:-%#: .=%#+--@= -@-.:-+#%-.. :*%-:=+*. ",
42 " .+@. :=+*#= :%%#*+=:. .@*. ",
43 " .@= .-=-.. .-==. =@. ",
44 " :*%*-:##=+*#%. .%#*+-*%--+#*: ",
45 " .:+#- .@+ =@. -#+-. ",
46 " =#####+ ",
47 " ",
48 " ",
49 " ",
50];
51
52pub fn window_title(status: &str) -> String {
54 if status.is_empty() {
55 format!("{MARK} rpi")
56 } else {
57 format!("{MARK} rpi {status}")
58 }
59}
60
61fn style_logo_row(row: &str) -> String {
63 current_theme().colors.dim.fg(row)
64}
65
66fn render_lockup() -> Vec<String> {
67 let width = LOGO_ROWS
68 .iter()
69 .map(|row| visible_width(row))
70 .max()
71 .unwrap_or(0);
72 LOGO_ROWS
73 .iter()
74 .map(|row| {
75 let padded = format!(
76 "{row}{}",
77 " ".repeat(width.saturating_sub(visible_width(row)))
78 );
79 style_logo_row(&padded)
80 })
81 .collect()
82}
83
84pub struct BrandLockup;
86
87impl BrandLockup {
88 pub fn new() -> Self {
89 Self
90 }
91}
92
93impl Default for BrandLockup {
94 fn default() -> Self {
95 Self::new()
96 }
97}
98
99impl Component for BrandLockup {
100 fn render(&self, _width: usize) -> Vec<String> {
101 render_lockup()
102 }
103
104 fn invalidate(&self) {
105 }
107
108 fn as_any(&self) -> &dyn std::any::Any {
109 self
110 }
111}
112
113#[cfg(test)]
114mod tests {
115 use super::*;
116 use rpi_tui::ansi::{strip_ansi, visible_width};
117
118 fn plain() -> Vec<String> {
119 render_lockup().iter().map(|r| strip_ansi(r)).collect()
120 }
121
122 #[test]
123 fn logo_has_the_readme_lockup_shape() {
124 let rows = plain();
125 assert_eq!(rows.len(), 32);
126 assert!(rows.iter().any(|row| row.contains("#")));
127 assert!(rows.iter().any(|row| row.contains("+=")));
128 assert!(rows[3].contains("+%###%*"));
129 assert!(rows[28].contains("=#####+"));
130 }
131
132 #[test]
133 fn logo_rows_have_stable_terminal_geometry() {
134 let rows = plain();
135 let widths: Vec<usize> = rows.iter().map(|row| visible_width(row)).collect();
136 assert!(widths.iter().all(|width| *width == widths[0]));
137 assert_eq!(widths[0], 64);
138 }
139
140 #[test]
141 fn title_keeps_the_logo_identity_and_status_last() {
142 assert_eq!(window_title(""), "@ rpi");
143 assert_eq!(window_title("⟳"), "@ rpi ⟳");
144 assert_eq!(window_title("↻"), "@ rpi ↻");
145 assert!(!window_title("⟳").contains('\n'));
146 }
147}