From 43d5cbd4aa4e6353c658761e091088f77fcc81c3 Mon Sep 17 00:00:00 2001 From: Valerie Wolfe Date: Mon, 15 Jul 2024 13:21:43 -0400 Subject: [PATCH] hug: initial implementation --- README.md | 4 ++++ hug/.gitignore | 2 ++ hug/Cargo.toml | 13 +++++++++++++ hug/src/main.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 hug/.gitignore create mode 100644 hug/Cargo.toml create mode 100644 hug/src/main.rs diff --git a/README.md b/README.md index 4b351f4..b8df0d8 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ Gets Windows environment variables from DOS. A hacked-together utility for sending WSL variables back to Windows shells. The utility runs in WSL, and companion scripts run in Windows. +## `hug` + +A wrapper for turning binary-output text into normal text. + ## `mkwin` A Linux utility to quickly make a bash script to run a Windows executable with diff --git a/hug/.gitignore b/hug/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/hug/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/hug/Cargo.toml b/hug/Cargo.toml new file mode 100644 index 0000000..088140e --- /dev/null +++ b/hug/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "hug" +version = "0.0.1" +edition = "2021" + +[profile.release] +opt-level = 's' +codegen-units = 1 +debug = false +lto = true +panic = "abort" +strip = "symbols" + diff --git a/hug/src/main.rs b/hug/src/main.rs new file mode 100644 index 0000000..4ea44a6 --- /dev/null +++ b/hug/src/main.rs @@ -0,0 +1,31 @@ +use std::{ + env, net::ToSocketAddrs, process::{ Command, Stdio } +}; + +fn main() { + let mut args: Vec = env::args().collect(); + args.remove(0); + + let target = args.remove(0); + let command = Command::new(target) + .args(args) + .stderr(Stdio::inherit()) + .output(); + if let Ok(output) = command { + let mut line = String::new(); + for byte in output.stdout { + match char::from_u32(byte.into()) { + Some('\n') => { + println!("{line}"); + line = String::new(); + }, + + Some('\0') | + None => continue, + + Some(c) => line.push(c), + } + } + } + +}