成都创新互联网站制作重庆分公司

go语言怎样改变回显颜色

这篇文章给大家分享的是有关go语言怎样改变回显颜色的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

站在用户的角度思考问题,与客户深入沟通,找到龙里网站设计与龙里网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站制作、网站设计、企业官网、英文网站、手机端网站、网站推广、域名注册雅安服务器托管、企业邮箱。业务覆盖龙里地区。

go语言改变回显颜色的方法:首先打开相应的go文件;然后通过“FontColor Color=Color{}”方法给字体颜色对象赋值;最后通过“func ColorPrint(s string, i int){}”方法输出有颜色的字体即可。

golang控制台颜色输出(for windows)

Go语言:控制台输出有颜色的字

本方法只限用于 Windows系统

应用场景

需要输出大量信息的运行日志(一般是服务器,Windows系统的)

某类客户端的调试界面(一般是游戏,特别是有第三方模组的)

代码示例

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)
}

感谢各位的阅读!关于go语言怎样改变回显颜色就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!


当前文章:go语言怎样改变回显颜色
文章转载:http://cxhlcq.com/article/jdpihs.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部