如何读取带有颜色属性的命令输出?

Is it possible to read a commands output with its color attributes. I mean, can we read the actual escape sequences.

for instance; A command output is red colored:

Hello

I want to read it as :

\033[31;1;4mHello\033[0m

Currently I am reading it like:

func stat(hash string) string {
    cmd := exec.Command("git", "show", "--stat", hash)
    out, err := cmd.Output()
    if err != nil {
        return err.Error()
    }
    return string(out)
}

Use the github.com/kr/pty library to run the command in a pty

This works for me

The escape sequences are visible in the output

package main

import (
    "github.com/kr/pty"
    "io"
    "os"
    "os/exec"
)

func main() {
    hash := os.Args[1]
    cmd := exec.Command("git", "show", "--stat", hash)
    f, err := pty.Start(cmd)
    if err != nil {
        panic(err)
    }

    io.Copy(os.Stdout, f)
}