Golang 命令行字体颜色

package main


import (
    "flag"
    "syscall"
)

func main() {

defer func() {return }()

cc := flag.Int("i",2,"Type: Int!")

flag.Parse()

count := int(-11)

objDll := syscall.NewLazyDLL("kernel32.dll")
colorHandle := objDll.NewProc("GetStdHandle")
consoleHandle,_,_ := colorHandle.Call(uintptr(count))
 
colorSet := objDll.NewProc("SetConsoleTextAttribute")
colorSet.Call(consoleHandle,uintptr(*cc))

}

调用API 实现命令行字体变色。

CMD都是一种背景颜色 一种字体颜色,从头到尾,改了一个就全部改变了。

有些同学喜欢一行一个颜色,一段话使用一种颜色,分开现实,以上程序即可实现。

使用方法cc 1~255

相关文章

什么是Go的接口? 接口可以说是一种类型,可以粗略的理解为他...
1、Golang指针 在介绍Golang指针隐式间接引用前,先简单说下...
1、概述 1.1 Protocol buffers定义 Protocol buffe...
判断文件是否存在,需要用到"os"包中的两个函数: os.Stat(...
1、编译环境 OS :Loongnix-Server Linux release 8.3 CPU指...
1、概述 Golang是一种强类型语言,虽然在代码中经常看到i:=1...