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

本文环境:Windows7系统、Go1.11.2版,本文适用于所有品牌的电脑。

推荐:《golang教程

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

更多相关文章

  1. 详细介绍使用XML资源文件来定义颜色,样式等
  2. Android color(颜色) 在XML文件和java代码中的代码详细介绍
  3. 关于定义颜色的10篇文章推荐
  4. 试水JetBrains官方新编程字体,真香!
  5. 这是个超棒的jQuery颜色选择器
  6. 9款最佳编程字体推荐
  7. 破解X眼电影字体动态加密|凹凸玩数据
  8. 破解大众点评的字体加密,这一篇就够了。
  9. matplotlib字体设置看这一篇就够了

随机推荐

  1. Linux使用技巧11--Ubuntu离线安装openssh
  2. Linux下pwn从入门到放弃
  3. uclinux-2008R1.5-RC3(bf561)到VDSP5的移
  4. Linux 常用命令之文件和目录
  5. Linux入门学习(五)
  6. linux的设置ip连接crt,修改主机名,映射,建文
  7. kernel module编程(七):通过读取proc文件进
  8. Linux基础命令杂记
  9. linux 系统级别安全
  10. 我已提取并尝试使用启动脚本(./start navi