fix: add ansi support and remove emoji

This commit is contained in:
2026-08-23 07:19:30 +05:00
parent 7dd2dd7f33
commit beab08cf67
5 changed files with 30 additions and 18 deletions
Generated
+10
View File
@@ -620,6 +620,15 @@ dependencies = [
"zeroize", "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]] [[package]]
name = "enum_dispatch" name = "enum_dispatch"
version = "0.3.13" version = "0.3.13"
@@ -2360,6 +2369,7 @@ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
"colored", "colored",
"enable-ansi-support",
"home", "home",
"russh", "russh",
"russh-sftp", "russh-sftp",
+1
View File
@@ -14,6 +14,7 @@ edition = "2024"
anyhow = "1.0.104" anyhow = "1.0.104"
clap = { version = "4.6.6", features = ["derive"] } clap = { version = "4.6.6", features = ["derive"] }
colored = "3.1.1" colored = "3.1.1"
enable-ansi-support = "0.3.1"
home = "0.5.12" home = "0.5.12"
russh = { version = "0.62.7", default-features = false, features = [ russh = { version = "0.62.7", default-features = false, features = [
"ring", "ring",
+4 -4
View File
@@ -28,10 +28,10 @@ xboctploy demo # задеплоить проект demo
```txt ```txt
deploying 'demo' deploying 'demo'
🟢 [Local] running: npm run build... Success! (1.2s) [Local] running: npm run build... Success! (1.2s)
🔵 [SFTP] transferring dist to /var/www/pages... Done! (14 file(s), 231.5 KiB) (829ms) [SFTP] transferring dist to /var/www/pages... Done! (14 file(s), 231.5 KiB) (829ms)
🟡 [Remote] running: pm2 restart pages... Success! (102ms) [Remote] running: pm2 restart pages... Success! (102ms)
🎉 Deploy successful! (total 2.3s) Deploy successful! (total 2.3s)
``` ```
## Конфигурация ## Конфигурация
+10 -14
View File
@@ -33,11 +33,11 @@ pub fn deploy(name: &str, project: &Project, dry_run: bool) -> Result<()> {
for cmd in local_cmds { for cmd in local_cmds {
let step = Instant::now(); let step = Instant::now();
if let Err(err) = local::execute(cmd, &project.workdir, &project.env) { 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); return Err(err);
} }
success_line( success_line(
"🟢 [Local]", "[Local]",
&format!("running: {cmd}..."), &format!("running: {cmd}..."),
"Success!", "Success!",
step.elapsed(), 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); let label = format!("transferring {} to {}...", rule.source.display(), target);
match result { match result {
Ok(stats) => success_line( Ok(stats) => success_line(
"🔵 [SFTP]", "[SFTP]",
&label, &label,
&format!("Done! ({stats})"), &format!("Done! ({stats})"),
step.elapsed(), step.elapsed(),
), ),
Err(err) => { Err(err) => {
fail_line("🔵 [SFTP]", &label, err.to_string()); fail_line("[SFTP]", &label, err.to_string());
return Err(err); return Err(err);
} }
} }
@@ -74,15 +74,11 @@ pub fn deploy(name: &str, project: &Project, dry_run: bool) -> Result<()> {
for cmd in remote_cmds { for cmd in remote_cmds {
let step = Instant::now(); let step = Instant::now();
if let Err(err) = session.exec(cmd) { if let Err(err) = session.exec(cmd) {
fail_line( fail_line("[Remote]", &format!("running: {cmd}..."), err.to_string());
"🟡 [Remote]",
&format!("running: {cmd}..."),
err.to_string(),
);
return Err(err); return Err(err);
} }
success_line( success_line(
"🟡 [Remote]", "[Remote]",
&format!("running: {cmd}..."), &format!("running: {cmd}..."),
"Success!", "Success!",
step.elapsed(), step.elapsed(),
@@ -91,7 +87,7 @@ pub fn deploy(name: &str, project: &Project, dry_run: bool) -> Result<()> {
} }
println!( println!(
"🎉 {} (total {})", "{} (total {})",
"Deploy successful!".green().bold(), "Deploy successful!".green().bold(),
fmt_dur(total.elapsed()) 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]) { fn print_plan(project: &Project, local_cmds: &[String], remote_cmds: &[String]) {
println!("dry-run plan:"); println!("dry-run plan:");
for cmd in local_cmds { for cmd in local_cmds {
println!(" 🟢 [Local] {cmd}"); println!(" [Local] {cmd}");
} }
for rule in &project.sync { for rule in &project.sync {
println!( println!(
" 🔵 [SFTP] {} -> {}", " [SFTP] {} -> {}",
rule.source.display(), rule.source.display(),
rule.target.display() rule.target.display()
); );
} }
for cmd in remote_cmds { for cmd in remote_cmds {
println!(" 🟡 [Remote] {cmd}"); println!(" [Remote] {cmd}");
} }
println!("{}", "nothing executed".dimmed()); println!("{}", "nothing executed".dimmed());
} }
+5
View File
@@ -12,6 +12,11 @@ use clap::Parser;
use colored::Colorize; use colored::Colorize;
fn main() -> ExitCode { fn main() -> ExitCode {
#[cfg(windows)]
if enable_ansi_support::enable_ansi_support().is_err() {
colored::control::set_override(false);
}
let cli = cli::Cli::parse(); let cli = cli::Cli::parse();
match run(&cli) { match run(&cli) {
Ok(()) => ExitCode::SUCCESS, Ok(()) => ExitCode::SUCCESS,