How to change the echo color in go language
The method of changing the echo color in go language: first open the corresponding go file; then assign a value to the font color object through the "FontColor Color=Color{}" method; finally use "func ColorPrint(s string, i int ){}" method to output colored fonts.
Environment of this article: Windows 7 system, Go1.11.2 version, this article is applicable to all brands of computers.
Recommended: "golang tutorial"
golang console color output (for windows)
Go language: console Output colored words
This method is only applicable to Windows systems
Application scenarios
Run logs that need to output a large amount of information (usually servers , Windows system)
Debugging interface of a certain type of client (usually games, especially those with third-party modules)
Code examples
package main import ( "syscall" ) var ( kernel32 *syscall.LazyDLL = syscall.NewLazyDLL(`kernel32.dll`) proc *syscall.LazyProc = kernel32.NewProc(`SetConsoleTextAttribute`) CloseHandle *syscall.LazyProc = kernel32.NewProc(`CloseHandle`) // 给字体颜色对象赋值 FontColor Color = Color{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} ) type Color struct { black int // 黑色 blue int // 蓝色 green int // 绿色 cyan int // 青色 red int // 红色 purple int // 紫色 yellow int // 黄色 light_gray int // 淡灰色(系统默认值) gray int // 灰色 light_blue int // 亮蓝色 light_green int // 亮绿色 light_cyan int // 亮青色 light_red int // 亮红色 light_purple int // 亮紫色 light_yellow int // 亮黄色 white int // 白色 } // 输出有颜色的字体 func ColorPrint(s string, i int) { handle, _, _ := proc.Call(uintptr(syscall.Stdout), uintptr(i)) print(s) CloseHandle.Call(handle) } func main() { ColorPrint(`红色`, FontColor.red) ColorPrint(`蓝色`, FontColor.blue) ColorPrint(`白色`, FontColor.white) }
The above is the detailed content of How to change the echo color in go language. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Which libraries in Go are developed by large companies or well-known open source projects? When programming in Go, developers often encounter some common needs, ...

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

The difference between string printing in Go language: The difference in the effect of using Println and string() functions is in Go...

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

Regarding the problem of custom structure tags in Goland When using Goland for Go language development, you often encounter some configuration problems. One of them is...

Go pointer syntax and addressing problems in the use of viper library When programming in Go language, it is crucial to understand the syntax and usage of pointers, especially in...

Why does map iteration in Go cause all values to become the last element? In Go language, when faced with some interview questions, you often encounter maps...

Go language slice index: Why does a single-element slice intercept from index 1 without an error? In Go language, slices are a flexible data structure that can refer to the bottom...
