1use std::io::{self, IsTerminal, Write};
2
3const LOGO: [&str; 6] = [
4 r" ██╗ ███████╗ █████╗ ███╗ ██╗ ██████╗████████╗██╗ ██╗",
5 r" ██║ ██╔════╝██╔══██╗████╗ ██║ ██╔════╝╚══██╔══╝╚██╗██╔╝",
6 r" ██║ █████╗ ███████║██╔██╗ ██║ ██║ ██║ ╚███╔╝ ",
7 r" ██║ ██╔══╝ ██╔══██║██║╚██╗██║ ██║ ██║ ██╔██╗ ",
8 r" ███████╗███████╗██║ ██║██║ ╚████║ ╚██████╗ ██║ ██╔╝ ██╗",
9 r" ╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝",
10];
11
12const TAGLINE: &str = "Context Runtime for AI Agents";
13
14pub fn print_logo_animated() {
15 let cfg = crate::core::config::Config::load();
16 let t = crate::core::theme::load_theme(&cfg.theme);
17 print_logo_animated_themed(&t);
18}
19
20pub fn print_logo_animated_themed(t: &crate::core::theme::Theme) {
21 if crate::core::theme::no_color() {
22 print_logo_plain();
23 return;
24 }
25 if !io::stdout().is_terminal() {
26 print_logo_themed_static(t);
27 return;
28 }
29
30 let mut stdout = io::stdout();
31 let frames = 28;
32 let frame_ms = 45;
33 let top_padding = 2;
34
35 let _ = writeln!(stdout);
36 let _ = writeln!(stdout);
37
38 for frame in 0..frames {
39 if frame > 0 {
40 print!("\x1b[{}A", LOGO.len() + 2 + top_padding);
41 for _ in 0..top_padding {
42 let _ = writeln!(stdout);
43 }
44 }
45
46 let wave_offset = frame as f64 / frames as f64;
47
48 for (i, line) in LOGO.iter().enumerate() {
49 let chars: Vec<char> = line.chars().collect();
50 let max_j = chars.len().max(1) as f64;
51 let mut buf = String::with_capacity(chars.len() * 20);
52
53 for (j, ch) in chars.iter().enumerate() {
54 if *ch == ' ' {
55 buf.push(' ');
56 continue;
57 }
58 let pos = j as f64 / max_j + i as f64 * 0.15;
59 let blend = ((pos + wave_offset * 2.0) * std::f64::consts::PI)
60 .sin()
61 .mul_add(0.5, 0.5);
62 let c = t.primary.lerp(&t.secondary, blend);
63 buf.push_str(&c.fg());
64 buf.push(*ch);
65 }
66 buf.push_str("\x1b[0m");
67 let _ = writeln!(stdout, "{buf}");
68 }
69
70 let tag_blend = ((wave_offset * 2.0 + 1.0) * std::f64::consts::PI)
71 .sin()
72 .mul_add(0.5, 0.5);
73 let tag_color = t.muted.lerp(&t.accent, tag_blend * 0.5);
74 let _ = writeln!(stdout, "{} {TAGLINE}\x1b[0m", tag_color.fg());
75 let _ = writeln!(stdout);
76
77 let _ = stdout.flush();
78 std::thread::sleep(std::time::Duration::from_millis(frame_ms));
79 }
80
81 print!("\x1b[{}A", LOGO.len() + 2 + top_padding);
82 print_logo_themed_static(t);
83}
84
85pub fn print_logo_static() {
86 let cfg = crate::core::config::Config::load();
87 let t = crate::core::theme::load_theme(&cfg.theme);
88 print_logo_themed_static(&t);
89}
90
91fn print_logo_themed_static(t: &crate::core::theme::Theme) {
92 if crate::core::theme::no_color() {
93 print_logo_plain();
94 return;
95 }
96 let mut stdout = io::stdout();
97
98 let _ = writeln!(stdout);
99 let _ = writeln!(stdout);
100
101 for (i, line) in LOGO.iter().enumerate() {
102 let chars: Vec<char> = line.chars().collect();
103 let mut buf = String::with_capacity(chars.len() * 20);
104
105 for (j, ch) in chars.iter().enumerate() {
106 if *ch == ' ' {
107 buf.push(' ');
108 continue;
109 }
110 let progress = if chars.len() > 1 {
111 j as f64 / (chars.len() - 1) as f64
112 } else {
113 0.5
114 };
115 let row_t = i as f64 / (LOGO.len() - 1).max(1) as f64;
116 let blend = (progress + row_t * 0.3).min(1.0);
117 let c = t.primary.lerp(&t.secondary, blend);
118 buf.push_str(&c.fg());
119 buf.push(*ch);
120 }
121 buf.push_str("\x1b[0m");
122 let _ = writeln!(stdout, "{buf}");
123 }
124
125 let _ = writeln!(stdout, "{} {TAGLINE}\x1b[0m", t.muted.fg());
126 let _ = writeln!(stdout);
127 let _ = stdout.flush();
128}
129
130fn print_logo_plain() {
131 println!();
132 println!();
133 for line in &LOGO {
134 println!("{line}");
135 }
136 println!(" {TAGLINE}");
137 println!();
138}
139
140#[allow(clippy::many_single_char_names)] pub fn print_command_box() {
142 use crate::core::theme;
143 let cfg = crate::core::config::Config::load();
144 let theme = theme::load_theme(&cfg.theme);
145 let dim = theme::dim();
146 let bold = theme::bold();
147 let rst = theme::rst();
148 let cmd = theme.accent.fg();
149 let ok = theme.success.fg();
150 let m = theme.muted.fg();
151
152 println!(" {dim}┌─────────────────────────────────────────────────────────┐{rst}");
153 println!(
154 " {dim}│{rst} {cmd}{bold}lean-ctx gain{rst} {m}Token savings dashboard{rst} {dim}│{rst}"
155 );
156 println!(
157 " {dim}│{rst} {cmd}{bold}lean-ctx dashboard{rst} {m}Web analytics (browser){rst} {dim}│{rst}"
158 );
159 println!(
160 " {dim}│{rst} {cmd}{bold}lean-ctx heatmap{rst} {m}Project context heat map{rst} {dim}│{rst}"
161 );
162 println!(
163 " {dim}│{rst} {cmd}{bold}lean-ctx benchmark{rst} {m}Test compression quality{rst} {dim}│{rst}"
164 );
165 println!(
166 " {dim}│{rst} {cmd}{bold}lean-ctx config{rst} {m}Edit settings{rst} {dim}│{rst}"
167 );
168 println!(
169 " {dim}│{rst} {cmd}{bold}lean-ctx doctor{rst} {m}Verify installation{rst} {dim}│{rst}"
170 );
171 println!(
172 " {dim}│{rst} {cmd}{bold}lean-ctx update{rst} {m}Self-update to latest{rst} {dim}│{rst}"
173 );
174 println!(" {dim}│{rst} {cmd}{bold}lean-ctx off{rst} / {cmd}{bold}on{rst} {m}Toggle compression{rst} {dim}│{rst}");
175 println!(
176 " {dim}│{rst} {cmd}{bold}lean-ctx report-issue{rst} {m}Report a bug (auto-diagnostics){rst} {dim}│{rst}"
177 );
178 println!(" {dim}│{rst} {cmd}{bold}lean-ctx contribute{rst} {m}Share anonymized compression stats{rst}{dim}│{rst}");
179 println!(
180 " {dim}│{rst} {cmd}{bold}lean-ctx uninstall{rst} {m}Clean removal{rst} {dim}│{rst}"
181 );
182 println!(" {dim}└─────────────────────────────────────────────────────────┘{rst}");
183 println!(" {ok}Ready!{rst} Your next AI command will be automatically optimized.");
184 println!(" {dim}Docs: https://leanctx.com/docs{rst}");
185 println!();
186}
187
188pub fn print_step_header(step: u8, total: u8, title: &str) {
189 let dim = "\x1b[2m";
190 let bold = "\x1b[1m";
191 let cyan = "\x1b[36m";
192 let rst = "\x1b[0m";
193 println!();
194 println!(" {cyan}{bold}[{step}/{total}]{rst} {bold}{title}{rst}");
195 println!(" {dim}─────────────────────────────────────────────────────{rst}");
196}
197
198pub fn print_status_ok(msg: &str) {
199 println!(" \x1b[32m✓\x1b[0m {msg}");
200}
201
202pub fn print_status_skip(msg: &str) {
203 println!(" \x1b[2m○\x1b[0m \x1b[2m{msg}\x1b[0m");
204}
205
206pub fn print_status_new(msg: &str) {
207 println!(" \x1b[1;32m✓\x1b[0m \x1b[1m{msg}\x1b[0m");
208}
209
210pub fn print_status_warn(msg: &str) {
211 println!(" \x1b[33m⚠\x1b[0m {msg}");
212}
213
214pub fn spinner_tick(msg: &str, frame: usize) {
215 let frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
216 let ch = frames[frame % frames.len()];
217 print!("\r \x1b[36m{ch}\x1b[0m {msg}");
218 let _ = io::stdout().flush();
219}
220
221pub fn spinner_done(msg: &str) {
222 print!("\r \x1b[32m✓\x1b[0m {msg}\x1b[K\n");
223 let _ = io::stdout().flush();
224}
225
226pub fn print_setup_header() {
227 let dim = "\x1b[2m";
228 let bold = "\x1b[1m";
229 let green = "\x1b[32m";
230 let rst = "\x1b[0m";
231 println!();
232 println!(" {dim}╭──────────────────────────────────────────╮{rst}");
233 println!(
234 " {dim}│{rst} {green}{bold}◆ lean-ctx setup{rst} {dim}│{rst}"
235 );
236 println!(" {dim}│{rst} {dim}Configuring your development environment{rst} {dim}│{rst}");
237 println!(" {dim}╰──────────────────────────────────────────╯{rst}");
238 println!();
239}