From ef4f8b2dab478dc8b1db0e220566e6733048551b Mon Sep 17 00:00:00 2001 From: 29 <791603901@qq.com> Date: Wed, 4 Dec 2024 16:57:03 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Implement=20`force-ansi`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 21 ++++++++++++++++++++- Cargo.toml | 1 + src/main.rs | 29 ++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 673ce82..c18f4d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,7 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" name = "force-ansi" version = "0.0.2" dependencies = [ + "nu-ansi-term 0.50.1", "tracing", "tracing-subscriber", ] @@ -131,6 +132,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "nu-ansi-term" +version = "0.50.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399" +dependencies = [ + "windows-sys", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -268,7 +278,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ "chrono", - "nu-ansi-term", + "nu-ansi-term 0.46.0", "sharded-slab", "smallvec", "thread_local", @@ -374,6 +384,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.6" diff --git a/Cargo.toml b/Cargo.toml index 377d8b6..fea5150 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ default-run = "force-ansi" rust-version = "1.63.0" [dependencies] +nu-ansi-term = "0.50.1" tracing = "0.1.41" tracing-subscriber = { version = "0.3.19", features = ["chrono"] } diff --git a/src/main.rs b/src/main.rs index e7a11a9..eb0ebad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,30 @@ +use std::{ + env::args_os, + process::{exit, Command}, +}; + fn main() { - println!("Hello, world!"); + #[cfg(windows)] + nu_ansi_term::enable_ansi_support().ok(); + + let mut args = args_os().skip(1); + exit(match args.next() { + None => -1, + Some(program) => match Command::new(program).args(args).spawn() { + Err(err) => { + eprintln!("{}", err); + -2 + } + Ok(mut child) => match child.wait() { + Err(err) => { + eprintln!("{}", err); + -3 + } + Ok(code) => match code.code() { + None => -4, + Some(code) => code, + }, + }, + }, + }); }