Go how to output ANSI color code

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

This bee upgrade to the 1.5 version, in the execution of bee version will be output a color Bee logo, many people feel very magical, in fact, this is the ANSI color code.

In fact, in Linux, we write C language easily can achieve this effect.

The specific writing format is as follows:

格式:\033[显示方式;前景色;背景色m 说明:前景色            背景色           颜色---------------------------------------30                40              黑色31                41              红色32                42              绿色33                43              黃色34                44              蓝色35                45              紫红色36                46              青蓝色37                47              白色显示方式           意义-------------------------0                终端默认设置1                高亮显示4                使用下划线5                闪烁7                反白显示8                不可见 例子:\033[1;31;40m    
  
   \033[0m          
  
   

For more information, please refer to Https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

But it's hard to do it under Windows.

The WIN32 console does not have support for ANSI escape sequences at all until Windows "Threshold 2". [Some] replacements or additions for the console window such as JP software ' s TCC (formerly 4NT), Michael J. Mefford ' s ansi.com, Jason Hood ' s ansicon[11] and MAXIMUS5 ' s ConEmu do interpret ANSI escape sequences printed by programs.

From this paragraph can be seen win 10 only support.

Inside unclear asked Baidu, foreign affairs unclear ask Google. Search to Https://github.com/fatih/color this artifact.

Go get Github.com/fatih/color

Below I will imitate bee to write a small program.

package mainimport ("fmt""github.com/fatih/color")func main() {beeStrUp := `______| ___ \| |_/ /  ___   ___| ___ \ / _ \ / _ \| |_/ /|  __/|  __/\____/  \___| \___| v1.5.0`beeStrDown := `├── Beego     : 1.7.0├── GoVersion : go1.6.2├── GOOS      : windows├── GOARCH    : amd64├── NumCPU    : 8├── GOPATH    : x:\Eagle\go├── GOROOT    : y:\Go\├── Compiler  : gc└── Date      : Friday, 19 Aug 2016`color.Set(color.FgMagenta, color.Bold)defer color.Unset()fmt.Println(beeStrUp)color.Set(color.FgGreen, color.Bold)fmt.Println(beeStrDown)}

Operation Result:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.