Golang终端彩色输出

终端彩色输出
func main() {
    fmt.Printf("\x1b[%dmhello world 30: 黑 \x1b[0m\n", 30)
    fmt.Printf("\x1b[%dmhello world 31: 红 \x1b[0m\n", 31)
    fmt.Printf("\x1b[%dmhello world 32: 绿 \x1b[0m\n", 32)
    fmt.Printf("\x1b[%dmhello world 33: 黄 \x1b[0m\n", 33)
    fmt.Printf("\x1b[%dmhello world 34: 蓝 \x1b[0m\n", 34)
    fmt.Printf("\x1b[%dmhello world 35: 紫 \x1b[0m\n", 35)
    fmt.Printf("\x1b[%dmhello world 36: 深绿 \x1b[0m\n", 36)
    fmt.Printf("\x1b[%dmhello world 37: 白色 \x1b[0m\n", 37)

    fmt.Printf("\x1b[%d;%dmhello world \x1b[0m 47: 白色 30: 黑 \n", 47, 30)
    fmt.Printf("\x1b[%d;%dmhello world \x1b[0m 46: 深绿 31: 红 \n", 46, 31)
    fmt.Printf("\x1b[%d;%dmhello world \x1b[0m 45: 紫   32: 绿 \n", 45, 32)
    fmt.Printf("\x1b[%d;%dmhello world \x1b[0m 44: 蓝   33: 黄 \n", 44, 33)
    fmt.Printf("\x1b[%d;%dmhello world \x1b[0m 43: 黄   34: 蓝 \n", 43, 34)
    fmt.Printf("\x1b[%d;%dmhello world \x1b[0m 42: 绿   35: 紫 \n", 42, 35)
    fmt.Printf("\x1b[%d;%dmhello world \x1b[0m 41: 红   36: 深绿 \n", 41, 36)
    fmt.Printf("\x1b[%d;%dmhello world \x1b[0m 40: 黑   37: 白色 \n", 40, 37)
}
终端显示
image.png
取值范围
前景  背景  颜色
30  40  黑色
31  41  红色
32  42  绿色
33  43  黄色
34  44  蓝色
35  45  紫色
36  46  深绿
37  47  白色
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容