drphfy1198 2019-05-09 12:30
浏览 32
已采纳

如何为没有第三方pkg的文本设置颜色

I want some text to be colored red and green. if the value < 0 then the color will be red and if the value > 0 then color will be green:

if x < 0 {
    fmt.Println("This line will be Red")
} else {
    fmt.Println("This line will be Green")
}

I want to know how to do that with the standard library not with third party pkg. How I can do that?

  • 写回答

1条回答 默认 最新

  • dqan70724 2019-05-09 12:34
    关注

    You can use:

    if x < 0 {
        fmt.Println("\x1b[31;1m This line will be Red \x1b[0m")
    } else {
        fmt.Println("\x1b[32;1m This line will be Green \x1b[0m")
    }
    

    You can play with the first number to change the color: [31,32,33...] and you always end with \x1b[0m.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能