我想捕获另一个进程的输出(例如git status),对其进行处理,并使用所有样式(粗体、斜体、下划线)和颜色进行打印。进一步处理它对我来说非常重要String,我不想只打印它。
在 Unix 世界中,我认为这会涉及转义码,我不确定 Windows 世界,但这对我也很重要。
我知道如何在没有颜色的情况下做到这一点:
fn exec_git() -> String {
let output = Command::new("git")
.arg("status")
.output()
.expect("failed to execute process");
String::from_utf8_lossy(&output.stdout).into_owned()
}
Run Code Online (Sandbox Code Playgroud)
也许我应该改用spawn?