diff --git a/Cargo.lock b/Cargo.lock index f3a779e..c7ba5e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -620,6 +620,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "enable-ansi-support" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea7457668b3da8a4b702f3d79e131aa3e81cd7e81cc95fb2d54fce9f182ecc77" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "enum_dispatch" version = "0.3.13" @@ -2360,6 +2369,7 @@ dependencies = [ "anyhow", "clap", "colored", + "enable-ansi-support", "home", "russh", "russh-sftp", diff --git a/Cargo.toml b/Cargo.toml index bef1a62..2a2225b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ edition = "2024" anyhow = "1.0.104" clap = { version = "4.6.6", features = ["derive"] } colored = "3.1.1" +enable-ansi-support = "0.3.1" home = "0.5.12" russh = { version = "0.62.7", default-features = false, features = [ "ring", diff --git a/README.md b/README.md index d1fe539..3d64272 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,10 @@ xboctploy demo # задеплоить проект demo ```txt deploying 'demo' -🟢 [Local] running: npm run build... Success! (1.2s) -🔵 [SFTP] transferring dist to /var/www/pages... Done! (14 file(s), 231.5 KiB) (829ms) -🟡 [Remote] running: pm2 restart pages... Success! (102ms) -🎉 Deploy successful! (total 2.3s) +[Local] running: npm run build... Success! (1.2s) +[SFTP] transferring dist to /var/www/pages... Done! (14 file(s), 231.5 KiB) (829ms) +[Remote] running: pm2 restart pages... Success! (102ms) +Deploy successful! (total 2.3s) ``` ## Конфигурация diff --git a/src/deploy.rs b/src/deploy.rs index 8f5fd93..28e64a0 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -33,11 +33,11 @@ pub fn deploy(name: &str, project: &Project, dry_run: bool) -> Result<()> { for cmd in local_cmds { let step = Instant::now(); if let Err(err) = local::execute(cmd, &project.workdir, &project.env) { - fail_line("🟢 [Local]", &format!("running: {cmd}..."), err.to_string()); + fail_line("[Local]", &format!("running: {cmd}..."), err.to_string()); return Err(err); } success_line( - "🟢 [Local]", + "[Local]", &format!("running: {cmd}..."), "Success!", step.elapsed(), @@ -59,13 +59,13 @@ pub fn deploy(name: &str, project: &Project, dry_run: bool) -> Result<()> { let label = format!("transferring {} to {}...", rule.source.display(), target); match result { Ok(stats) => success_line( - "🔵 [SFTP]", + "[SFTP]", &label, &format!("Done! ({stats})"), step.elapsed(), ), Err(err) => { - fail_line("🔵 [SFTP]", &label, err.to_string()); + fail_line("[SFTP]", &label, err.to_string()); return Err(err); } } @@ -74,15 +74,11 @@ pub fn deploy(name: &str, project: &Project, dry_run: bool) -> Result<()> { for cmd in remote_cmds { let step = Instant::now(); if let Err(err) = session.exec(cmd) { - fail_line( - "🟡 [Remote]", - &format!("running: {cmd}..."), - err.to_string(), - ); + fail_line("[Remote]", &format!("running: {cmd}..."), err.to_string()); return Err(err); } success_line( - "🟡 [Remote]", + "[Remote]", &format!("running: {cmd}..."), "Success!", step.elapsed(), @@ -91,7 +87,7 @@ pub fn deploy(name: &str, project: &Project, dry_run: bool) -> Result<()> { } println!( - "🎉 {} (total {})", + "{} (total {})", "Deploy successful!".green().bold(), fmt_dur(total.elapsed()) ); @@ -101,17 +97,17 @@ pub fn deploy(name: &str, project: &Project, dry_run: bool) -> Result<()> { fn print_plan(project: &Project, local_cmds: &[String], remote_cmds: &[String]) { println!("dry-run plan:"); for cmd in local_cmds { - println!(" 🟢 [Local] {cmd}"); + println!(" [Local] {cmd}"); } for rule in &project.sync { println!( - " 🔵 [SFTP] {} -> {}", + " [SFTP] {} -> {}", rule.source.display(), rule.target.display() ); } for cmd in remote_cmds { - println!(" 🟡 [Remote] {cmd}"); + println!(" [Remote] {cmd}"); } println!("{}", "nothing executed".dimmed()); } diff --git a/src/main.rs b/src/main.rs index 20d9532..45ab005 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,11 @@ use clap::Parser; use colored::Colorize; fn main() -> ExitCode { + #[cfg(windows)] + if enable_ansi_support::enable_ansi_support().is_err() { + colored::control::set_override(false); + } + let cli = cli::Cli::parse(); match run(&cli) { Ok(()) => ExitCode::SUCCESS,