1use colored::Colorize;
2use console::Term;
3use parking_lot::Mutex;
4use ratatui::style::Color;
5use std::fmt::Write as _;
6
7pub use crate::tui::spinner::SpinnerState;
9
10pub const STARLIGHT: Color = Color::Rgb(255, 255, 240);
11pub const NEBULA_PURPLE: Color = Color::Rgb(167, 132, 239);
12pub const CELESTIAL_BLUE: Color = Color::Rgb(75, 115, 235);
13pub const SOLAR_YELLOW: Color = Color::Rgb(255, 225, 100);
14pub const AURORA_GREEN: Color = Color::Rgb(140, 255, 170);
15pub const PLASMA_CYAN: Color = Color::Rgb(20, 255, 255);
16pub const METEOR_RED: Color = Color::Rgb(255, 89, 70);
17pub const GALAXY_PINK: Color = Color::Rgb(255, 162, 213);
18pub const COMET_ORANGE: Color = Color::Rgb(255, 165, 0);
19pub const BLACK_HOLE: Color = Color::Rgb(0, 0, 0);
20
21static QUIET_MODE: std::sync::LazyLock<Mutex<bool>> =
23 std::sync::LazyLock::new(|| Mutex::new(false));
24
25#[inline]
27pub fn set_quiet_mode(enabled: bool) {
28 *QUIET_MODE.lock() = enabled;
29}
30
31#[inline]
33pub fn is_quiet_mode() -> bool {
34 *QUIET_MODE.lock()
35}
36
37#[inline]
39#[must_use]
40pub fn create_tui_spinner(message: &str) -> SpinnerState {
41 SpinnerState::with_message(message)
42}
43
44pub fn print_info(message: &str) {
45 if !is_quiet_mode() {
46 println!("{}", message.cyan().bold());
47 }
48}
49
50pub fn print_warning(message: &str) {
51 if !is_quiet_mode() {
52 println!("{}", message.yellow().bold());
53 }
54}
55
56pub fn print_error(message: &str) {
57 eprintln!("{}", message.red().bold());
59}
60
61pub fn print_success(message: &str) {
62 if !is_quiet_mode() {
63 println!("{}", message.green().bold());
64 }
65}
66
67pub fn print_bordered_content(content: &str) {
69 if !is_quiet_mode() {
70 let border = "━".repeat(50).bright_purple();
71 println!("{border}");
72 println!("{content}");
73 println!("{border}");
74 }
75}
76
77pub fn print_message(message: &str) {
79 if !is_quiet_mode() {
80 println!("{message}");
81 }
82}
83
84pub fn print_newline() {
86 if !is_quiet_mode() {
87 println!();
88 }
89}
90
91#[must_use]
92pub fn create_gradient_text(text: &str) -> String {
93 const GRADIENT: &[(u8, u8, u8)] = &[
94 (129, 0, 255), (134, 51, 255),
96 (139, 102, 255),
97 (144, 153, 255),
98 (149, 204, 255), ];
100
101 apply_gradient(text, GRADIENT)
102}
103
104#[must_use]
105pub fn create_secondary_gradient_text(text: &str) -> String {
106 const GRADIENT: &[(u8, u8, u8)] = &[
107 (75, 0, 130), (106, 90, 205), (138, 43, 226), (148, 0, 211), (153, 50, 204), ];
113
114 apply_gradient(text, GRADIENT)
115}
116
117#[must_use]
118fn apply_gradient(text: &str, gradient: &[(u8, u8, u8)]) -> String {
119 let chars: Vec<char> = text.chars().collect();
120
121 if chars.is_empty() || gradient.is_empty() {
122 return String::new();
123 }
124
125 let chars_len = chars.len();
126 let gradient_len = gradient.len();
127 let mut result = String::with_capacity(text.len() * 20); for (i, &c) in chars.iter().enumerate() {
130 let index = if chars_len == 1 {
131 0
132 } else {
133 i * (gradient_len - 1) / (chars_len - 1)
134 };
135 let (r, g, b) = gradient[index];
136 let _ = write!(result, "{}", c.to_string().truecolor(r, g, b));
137 }
138
139 result
140}
141
142pub fn write_gradient_text(
143 term: &Term,
144 text: &str,
145 gradient: &[(u8, u8, u8)],
146) -> std::io::Result<()> {
147 let gradient_text = apply_gradient(text, gradient);
148 term.write_line(&gradient_text)
149}
150
151pub fn write_colored_text(term: &Term, text: &str, color: (u8, u8, u8)) -> std::io::Result<()> {
152 let (r, g, b) = color;
153 let colored_text = text.truecolor(r, g, b);
154 term.write_line(&colored_text)
155}
156
157pub fn write_bold_text(term: &Term, text: &str) -> std::io::Result<()> {
158 let bold_text = text.bold();
159 term.write_line(&bold_text)
160}