fatih / color

Color package for Go (golang)
https://pkg.go.dev/github.com/fatih/color
MIT License
7.3k stars 615 forks source link

In the Windows, press Ctrl+C, the characters in the cmd.exe are displayed in incorrect colors. #205

Open hcbb199 opened 1 year ago

hcbb199 commented 1 year ago

If you press Ctrl+C when waiting for user input during interaction, the color of the output characters in cmd.exe is incorrect.

package main

import (
    "bufio"
    "github.com/fatih/color"
    "os"
    "strings"
)

var (
    Info  = color.New(color.Bold, color.FgHiGreen)
    Error = color.New(color.Bold, color.FgHiRed)
)

func main() {
    Info.Println("input your color: ")
    reader := bufio.NewReader(os.Stdin)
    input, _, err := reader.ReadLine()
    if err != nil {
        Error.Println(err.Error())
        return
    }
    Info.Println("your input is " + strings.TrimSpace(string(input)))
}

image