1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! The startup brand lockup, generated from the README logo with RASCII.
//!
//! Regenerate with `cargo install rascii_art --version 0.4.5 --locked`, then:
//! `rascii docs/images/rpi-logo.jpg --width 64 --height 32 --invert --charset " .:-=+*#%@"`.
//!
//! The logo is kept as text rather than loading the README JPEG so it works in
//! plain terminals, remote sessions, and terminals without image protocols.
//! Its rows use fixed single-cell geometry and are scaled down for the
//! terminal's character aspect ratio.
use rpi_tui::{ansi::visible_width, theme as current_theme, Component};
/// A compact ASCII approximation used in the terminal window/tab title.
/// The full gear is rendered by [`render_lockup`].
pub const MARK: &str = "@";
const LOGO_ROWS: [&str; 32] = [
" ",
" ",
" ",
" +%###%* ",
" .-+*: .@= -@. :**-. ",
" -*#+:-%*=*###. .###*=+%=:+##- ",
" -@: .=-:. .:-=. :@= ",
" .#%. .:=*#%%%%%%%#*=:. .##. ",
" .+=:.-#*: .-*%#+-:. ..-+#%*-. :*%-.:-+: ",
" :%+=+*#- .=%#-. .-#%+. :##+=+@: ",
" :@= -%#: :#@- =@: ",
" :*%=. =@= =@+. .=%*: ",
" .@* =@= -#-----*- -@+ +@: ",
" =@: :@* .=#%*+++*%#=. +@- .@= ",
" :+*##+ *@. :%%-..-=-: :#%: .@* +##*+- ",
" *%.. %% #%..+@*=*@*..#%. *% ..#*. ",
" *% .%% .#= :@+ =@: +@: *@ #*. ",
" -###*= *@. ....::. :@@*+*@*..#%. -*- .%# =*###= ",
" =@. :@+ .+@%#*#+ :@+---..-%%: :+: =@- .@+ ",
" .%* +@-.+@= :@= :+*%#=. -@- :@* +@. ",
" .-#*- +@=+@: :@= -@=. -@--@*. :*%=. ",
" :@+ -%@@: :@= -@- -@%@- =@: ",
" :%+:=+*- .=%::. :@= -@- ..-%=. :*+=:+@- ",
" .**=:-%#: .=%#+--@= -@-.:-+#%-.. :*%-:=+*. ",
" .+@. :=+*#= :%%#*+=:. .@*. ",
" .@= .-=-.. .-==. =@. ",
" :*%*-:##=+*#%. .%#*+-*%--+#*: ",
" .:+#- .@+ =@. -#+-. ",
" =#####+ ",
" ",
" ",
" ",
];
/// The startup lockup flattened into a terminal window/tab title.
pub fn window_title(status: &str) -> String {
if status.is_empty() {
format!("{MARK} rpi")
} else {
format!("{MARK} rpi {status}")
}
}
/// Apply the current theme to the monochrome ASCII output.
fn style_logo_row(row: &str) -> String {
current_theme().colors.dim.fg(row)
}
fn render_lockup() -> Vec<String> {
let width = LOGO_ROWS
.iter()
.map(|row| visible_width(row))
.max()
.unwrap_or(0);
LOGO_ROWS
.iter()
.map(|row| {
let padded = format!(
"{row}{}",
" ".repeat(width.saturating_sub(visible_width(row)))
);
style_logo_row(&padded)
})
.collect()
}
/// The startup logo. Add one to the welcome header.
pub struct BrandLockup;
impl BrandLockup {
pub fn new() -> Self {
Self
}
}
impl Default for BrandLockup {
fn default() -> Self {
Self::new()
}
}
impl Component for BrandLockup {
fn render(&self, _width: usize) -> Vec<String> {
render_lockup()
}
fn invalidate(&self) {
// Nothing is cached.
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use rpi_tui::ansi::{strip_ansi, visible_width};
fn plain() -> Vec<String> {
render_lockup().iter().map(|r| strip_ansi(r)).collect()
}
#[test]
fn logo_has_the_readme_lockup_shape() {
let rows = plain();
assert_eq!(rows.len(), 32);
assert!(rows.iter().any(|row| row.contains("#")));
assert!(rows.iter().any(|row| row.contains("+=")));
assert!(rows[3].contains("+%###%*"));
assert!(rows[28].contains("=#####+"));
}
#[test]
fn logo_rows_have_stable_terminal_geometry() {
let rows = plain();
let widths: Vec<usize> = rows.iter().map(|row| visible_width(row)).collect();
assert!(widths.iter().all(|width| *width == widths[0]));
assert_eq!(widths[0], 64);
}
#[test]
fn title_keeps_the_logo_identity_and_status_last() {
assert_eq!(window_title(""), "@ rpi");
assert_eq!(window_title("⟳"), "@ rpi ⟳");
assert_eq!(window_title("↻"), "@ rpi ↻");
assert!(!window_title("⟳").contains('\n'));
}
}