我想捕获另一个进程的输出(例如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()
}
也许我应该改用spawn?
我正在为我们的C编程课程分配创建一个基于控制台的小游戏,我决定通过添加文本颜色和文本背景使其更具代表性和独特性.
当我在寻找解决方案时,我发现这个方便的功能将按照我想要的方式完成我的项目,但问题是这部分我不明白:
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
where,BackC并ForgC给出整数,数据类型WORD只是unsigned short int的typedef.具体来说,我不明白的是这((BackC & 0x0F) << 4) + (ForgC & 0x0F)部分.谁能帮我这个?我知道我可以使用该功能,但我真的想知道该功能是如何工作的......谢谢!
这是完整的源代码(colorExample.c)
#include <windows.h>
#include <stdio.h>
void SetColorAndBackground(int ForgC, int BackC);
int main()
{
    SetColorAndBackground(10,1);   //color value range 0 up-to 256
    printf("what is text background color \n");
    SetColorAndBackground(11,1);
    printf("how about this?");
    getch();
    return 0;
}
void SetColorAndBackground(int ForgC, int BackC)
{
     WORD wColor = ((BackC & 0x0F) << …