deb: change ui/ux of pkh deb
This commit is contained in:
+49
-2
@@ -1,10 +1,12 @@
|
||||
/// Local context: execute commands locally
|
||||
/// Context driver: Does nothing
|
||||
use super::api::ContextDriver;
|
||||
use super::api::{ContextDriver, LineSink, Stream};
|
||||
use super::capture::pump;
|
||||
use std::io;
|
||||
use std::os::unix::fs::symlink;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
|
||||
pub struct LocalDriver;
|
||||
@@ -80,6 +82,51 @@ impl ContextDriver for LocalDriver {
|
||||
cmd.status()
|
||||
}
|
||||
|
||||
fn run_captured(
|
||||
&self,
|
||||
program: &str,
|
||||
args: &[String],
|
||||
env: &[(String, String)],
|
||||
cwd: Option<&str>,
|
||||
sink: Arc<dyn LineSink>,
|
||||
) -> io::Result<std::process::ExitStatus> {
|
||||
let mut cmd = Command::new(program);
|
||||
cmd.args(args).envs(env.iter().map(|(k, v)| (k, v)));
|
||||
// Best-effort: ask children not to emit ANSI colors; captured lines are
|
||||
// stripped anyway.
|
||||
cmd.env("NO_COLOR", "1");
|
||||
if let Some(dir) = cwd {
|
||||
cmd.current_dir(dir);
|
||||
}
|
||||
cmd.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.stdin(Stdio::null());
|
||||
|
||||
let mut child = cmd.spawn()?;
|
||||
let stdout = child.stdout.take();
|
||||
let stderr = child.stderr.take();
|
||||
|
||||
// One reader thread per stream; lines are forwarded to the sink as
|
||||
// they arrive so the UI stays live.
|
||||
let out_sink = sink.clone();
|
||||
let t_out =
|
||||
stdout.map(|r| std::thread::spawn(move || pump(r, Stream::Stdout, out_sink.as_ref())));
|
||||
let err_sink = sink.clone();
|
||||
let t_err =
|
||||
stderr.map(|r| std::thread::spawn(move || pump(r, Stream::Stderr, err_sink.as_ref())));
|
||||
|
||||
let status = child.wait();
|
||||
|
||||
if let Some(t) = t_out {
|
||||
let _ = t.join();
|
||||
}
|
||||
if let Some(t) = t_err {
|
||||
let _ = t.join();
|
||||
}
|
||||
|
||||
status
|
||||
}
|
||||
|
||||
fn run_output(
|
||||
&self,
|
||||
program: &str,
|
||||
|
||||
Reference in New Issue
Block a user