Skip to content

Commit 76ed6f9

Browse files
authored
Merge pull request #127 from bigjoe-io/main
fix issues
2 parents 9215ab9 + 21f5de3 commit 76ed6f9

File tree

7 files changed

+144
-43
lines changed

7 files changed

+144
-43
lines changed

crates/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ clap = { workspace = true }
2020
clap_complete = "4"
2121
anyhow = { workspace = true }
2222
colored = { workspace = true }
23+
owo-colors = "4"
2324
indicatif = { workspace = true }
2425
dialoguer = { workspace = true }
2526
tabled = { workspace = true }

crates/cli/src/commands/auth.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! `prism login` and `prism logout` — Manage API credentials for hosted services.
22
3-
use clap::{Args, Subcommand};
43
use anyhow::{Result, anyhow};
5-
use colored::Colorize;
4+
use clap::{Args, Subcommand};
65
use dialoguer::Select;
76
use rpassword::prompt_password;
87
use serde::{Deserialize, Serialize};
@@ -72,18 +71,23 @@ async fn login(
7271
config_path: Option<String>,
7372
output_format: &str,
7473
) -> Result<()> {
74+
let palette = crate::output::theme::ColorPalette::default();
75+
7576
// Determine provider name
7677
let provider = match provider_param {
7778
Some(p) => p,
7879
None => select_provider_interactive()?,
7980
};
8081

8182
// Prompt for API key securely
82-
let prompt = format!("Enter your API key for {}: ", provider.green());
83+
let prompt = format!(
84+
"Enter your API key for {}: ",
85+
palette.success_text(&provider)
86+
);
8387
let api_key = prompt_password(&prompt)?;
8488

8589
if api_key.trim().is_empty() {
86-
eprintln!("{}", "API key cannot be empty.".red());
90+
eprintln!("{}", palette.error_text("API key cannot be empty."));
8791
std::process::exit(1);
8892
}
8993

@@ -102,11 +106,11 @@ async fn login(
102106
});
103107
println!("{}", serde_json::to_string_pretty(&payload)?);
104108
} else {
105-
println!("✓ Credentials for {} saved.", provider.green());
109+
println!("✓ Credentials for {} saved.", palette.success_text(&provider));
106110
}
107111
}
108112
Err(e) => {
109-
eprintln!("{} {}", "Error:".red(), e);
113+
eprintln!("{} {}", palette.error_text("Error:"), e);
110114
std::process::exit(1);
111115
}
112116
}
@@ -120,6 +124,8 @@ async fn logout(
120124
config_path: Option<String>,
121125
output_format: &str,
122126
) -> Result<()> {
127+
let palette = crate::output::theme::ColorPalette::default();
128+
123129
// Determine provider name
124130
let provider = match provider_param {
125131
Some(p) => p,
@@ -141,7 +147,7 @@ async fn logout(
141147
});
142148
println!("{}", serde_json::to_string_pretty(&payload)?);
143149
} else {
144-
println!("✓ Credentials for {} removed.", provider.green());
150+
println!("✓ Credentials for {} removed.", palette.success_text(&provider));
145151
}
146152
}
147153
Ok(false) => {
@@ -157,11 +163,11 @@ async fn logout(
157163
});
158164
println!("{}", serde_json::to_string_pretty(&payload)?);
159165
} else {
160-
println!("No credentials found for {}.", provider.yellow());
166+
println!("No credentials found for {}.", palette.warning_text(&provider));
161167
}
162168
}
163169
Err(e) => {
164-
eprintln!("{} {}", "Error:".red(), e);
170+
eprintln!("{} {}", palette.error_text("Error:"), e);
165171
std::process::exit(1);
166172
}
167173
}

crates/cli/src/commands/diagnostic.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::path::{Path, PathBuf};
44
use std::time::{Duration, Instant};
55

66
use anyhow::Result;
7-
use colored::Colorize;
87
use directories::ProjectDirs;
8+
use crate::output::theme::ColorPalette;
99

1010
// ─── Args ────────────────────────────────────────────────────────────────────
1111

@@ -42,11 +42,12 @@ impl Status {
4242
}
4343
}
4444

45-
fn label(&self) -> colored::ColoredString {
45+
fn label(&self) -> String {
46+
let palette = ColorPalette::default();
4647
match self {
47-
Self::Ok => " OK ".green().bold(),
48-
Self::Warning(_) => " WARN ".yellow().bold(),
49-
Self::Error(_) => " ERROR ".red().bold(),
48+
Self::Ok => palette.success_text(" OK "),
49+
Self::Warning(_) => palette.warning_text(" WARN "),
50+
Self::Error(_) => palette.error_text(" ERROR "),
5051
}
5152
}
5253
}
@@ -264,21 +265,26 @@ fn dir_size_mib(path: &PathBuf) -> Result<u64> {
264265
// ─── Report ───────────────────────────────────────────────────────────────────
265266

266267
fn print_report(checks: &[Check], quiet: bool) {
268+
let palette = ColorPalette::default();
267269
let sep = "─".repeat(58);
268-
println!("\n {}", "Prism Diagnostic Report".bold());
269-
println!(" {}\n", sep.dimmed());
270+
println!("\n {}", palette.accent_text("Prism Diagnostic Report"));
271+
println!(" {}\n", palette.muted_text(&sep));
270272

271273
for check in checks {
272274
if quiet && check.status.is_ok() {
273275
continue;
274276
}
275277
println!(" [{}] {}", check.status.label(), check.name);
276278
if let Some(detail) = check.status.detail() {
277-
println!(" {} {}", "└─".dimmed(), detail.dimmed());
279+
println!(
280+
" {} {}",
281+
palette.muted_text("└─"),
282+
palette.muted_text(detail)
283+
);
278284
}
279285
}
280286

281-
println!("\n {}", sep.dimmed());
287+
println!("\n {}", palette.muted_text(&sep));
282288

283289
let warnings = checks
284290
.iter()
@@ -287,20 +293,21 @@ fn print_report(checks: &[Check], quiet: bool) {
287293
let errors = checks.iter().filter(|c| c.status.is_error()).count();
288294

289295
if errors == 0 && warnings == 0 {
290-
println!(" {}\n", "All checks passed.".green().bold());
296+
println!(" {}\n", palette.success_text("All checks passed."));
291297
} else {
292298
println!(
293299
" {} warning(s), {} error(s).\n",
294-
warnings.to_string().yellow(),
295-
errors.to_string().red()
300+
palette.warning_text(&warnings.to_string()),
301+
palette.error_text(&errors.to_string())
296302
);
297303
}
298304
}
299305

300306
// ─── Entry point ──────────────────────────────────────────────────────────────
301307

302308
pub async fn run(args: DiagnosticArgs) -> Result<()> {
303-
println!("{}", "Running diagnostics…".dimmed());
309+
let palette = ColorPalette::default();
310+
println!("{}", palette.muted_text("Running diagnostics..."));
304311

305312
let mut checks: Vec<Check> = Vec::new();
306313

crates/cli/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ struct Cli {
7777
/// Suppress non-essential output.
7878
#[arg(long, short, global = true)]
7979
quiet: bool,
80+
81+
/// Disable ANSI colors in terminal output.
82+
#[arg(long, global = true)]
83+
no_color: bool,
8084
}
8185

8286
#[derive(Subcommand)]
@@ -128,10 +132,13 @@ async fn main() -> anyhow::Result<()> {
128132
output = %cli.output,
129133
network_arg = %cli.network,
130134
verbose = cli.verbose,
135+
no_color = cli.no_color,
131136
config_loaded = loaded_config.is_some(),
132137
"CLI arguments parsed"
133138
);
134139

140+
output::theme::set_color_enabled(!cli.no_color);
141+
135142
let mut network = prism_core::network::config::resolve_network(&cli.network);
136143
if let Some(ref rpc_url) = cli.rpc_url {
137144
network.rpc_url = rpc_url.clone();

crates/cli/src/output/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod compact;
1212
pub mod human;
1313
pub mod json;
1414
pub mod renderers;
15+
pub mod theme;
1516

1617
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1718
pub enum OutputFormat {
@@ -69,8 +70,9 @@ pub fn print_resource_profile(
6970
renderers::BudgetBar::new("Memory", profile.total_memory, profile.memory_limit)
7071
.render()
7172
);
73+
let palette = theme::ColorPalette::default();
7274
for warning in &profile.warnings {
73-
println!("{} {warning}", colored::Colorize::yellow("⚠"));
75+
println!("{} {warning}", palette.warning_text("⚠"));
7476
}
7577
println!();
7678
print!("{}", renderers::render_heatmap(profile));
@@ -84,13 +86,14 @@ pub fn print_state_diff(diff: &StateDiff, output_format: &str) -> anyhow::Result
8486
OutputFormat::Json => println!("{}", serde_json::to_string_pretty(diff)?),
8587
OutputFormat::Short => println!("{}", format_state_diff_summary(diff)),
8688
OutputFormat::Human => {
87-
println!("{}", colored::Colorize::bold("State Diff"));
89+
let palette = theme::ColorPalette::default();
90+
println!("{}", palette.accent_text("State Diff"));
8891
for entry in &diff.entries {
8992
let symbol = match entry.change_type {
90-
DiffChangeType::Created => colored::Colorize::green("+"),
91-
DiffChangeType::Deleted => colored::Colorize::red("-"),
92-
DiffChangeType::Updated => colored::Colorize::yellow("~"),
93-
DiffChangeType::Unchanged => colored::Colorize::dimmed(" "),
93+
DiffChangeType::Created => palette.success_text("+"),
94+
DiffChangeType::Deleted => palette.error_text("-"),
95+
DiffChangeType::Updated => palette.warning_text("~"),
96+
DiffChangeType::Unchanged => palette.muted_text(" "),
9497
};
9598
println!("{symbol} {}", entry.key);
9699
}

crates/cli/src/output/renderers.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
33
#![allow(dead_code)]
44

5-
use colored::Colorize;
65
use prism_core::types::report::TransactionContext;
76
use prism_core::types::trace::ResourceProfile;
87
use tabled::{Table, Tabled};
8+
use crate::output::theme::ColorPalette;
99

1010
const BAR_WIDTH: usize = 10;
1111
const HEAT_BLOCKS: [&str; 4] = ["░", "▒", "▓", "█"];
@@ -31,8 +31,9 @@ impl<'a> SectionHeader<'a> {
3131
let border = format!("+{}+", "-".repeat(inner.chars().count()));
3232
let middle = format!("|{}|", inner);
3333

34-
let border = border.cyan().bold().to_string();
35-
let middle = middle.white().bold().to_string();
34+
let palette = ColorPalette::default();
35+
let border = palette.metadata_text(&border);
36+
let middle = palette.accent_text(&middle);
3637

3738
format!("{}\n{}\n{}", border, middle, border)
3839
}
@@ -61,12 +62,13 @@ impl BudgetBar {
6162
let empty = BAR_WIDTH.saturating_sub(filled);
6263
let bar_str = format!("{}{}", "█".repeat(filled), "░".repeat(empty));
6364

65+
let palette = ColorPalette::default();
6466
let colored_bar = if pct >= 0.9 {
65-
bar_str.red().bold().to_string()
67+
palette.error_text(&bar_str)
6668
} else if pct >= 0.7 {
67-
bar_str.yellow().to_string()
69+
palette.warning_text(&bar_str)
6870
} else {
69-
bar_str.green().to_string()
71+
palette.success_text(&bar_str)
7072
};
7173

7274
format!(
@@ -95,24 +97,26 @@ fn heat_cell(intensity: f64) -> String {
9597
let empty = BAR_WIDTH.saturating_sub(filled);
9698
let cell = format!("{}{}", block.repeat(filled), "░".repeat(empty));
9799

100+
let palette = ColorPalette::default();
98101
if intensity >= 0.75 {
99-
cell.red().bold().to_string()
102+
palette.error_text(&cell)
100103
} else if intensity >= 0.5 {
101-
cell.yellow().to_string()
104+
palette.warning_text(&cell)
102105
} else if intensity >= 0.25 {
103-
cell.cyan().to_string()
106+
palette.metadata_text(&cell)
104107
} else {
105-
cell.dimmed().to_string()
108+
palette.muted_text(&cell)
106109
}
107110
}
108111

109112
/// Render a resource heatmap grid from a `ResourceProfile`.
110113
pub fn render_heatmap(profile: &ResourceProfile) -> String {
111114
if profile.hotspots.is_empty() {
115+
let palette = ColorPalette::default();
112116
return format!(
113117
"{}\n {}\n",
114118
render_section_header("Resource Heatmap"),
115-
"No hotspot data available.".dimmed()
119+
palette.muted_text("No hotspot data available.")
116120
);
117121
}
118122

@@ -186,12 +190,13 @@ pub fn render_heatmap(profile: &ResourceProfile) -> String {
186190
}
187191

188192
out.push('\n');
193+
let palette = ColorPalette::default();
189194
out.push_str(&format!(
190195
" Legend: {} cold {} low {} medium {} hot\n",
191-
"░░░░░░░░░░".dimmed(),
192-
"▒▒▒▒▒▒▒▒▒▒".cyan(),
193-
"▓▓▓▓▓▓▓▓▓▓".yellow(),
194-
"██████████".red().bold(),
196+
palette.muted_text("░░░░░░░░░░"),
197+
palette.metadata_text("▒▒▒▒▒▒▒▒▒▒"),
198+
palette.warning_text("▓▓▓▓▓▓▓▓▓▓"),
199+
palette.error_text("██████████"),
195200
));
196201

197202
out

0 commit comments

Comments
 (0)