1 Star 0 Fork 0

Stefan / xgameCommon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
color_linux.go 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
Stefan 提交于 2020-05-09 19:48 . add common file.
package tool
//add by stefan for linux system.
import (
"fmt"
)
/*
Foreground Background Color
30 40 black
31 41 red
32 42 green
33 43 yellow
34 44 blue
35 45 Fuchsia
36 46 cyan
37 47 white
*/
const (
LinuxForeground_Black = 0x1E
LinuxForeground_Red = 0x1F
LinuxForeground_GREEN = 0x20
LinuxForeground_YELLOW = 0x21
LinuxForeground_BLUE = 0x22
LinuxForeground_FUCHSIA = 0x23
LinuxForeground_CYAN = 0x24
LinuxForeground_WHITE = 0x25
)
const (
LinuxBackground_Black = 0x28
LinuxBackground_Red = 0x29
LinuxBackground_GREEN = 0x2a
LinuxBackground_YELLOW = 0x2b
LinuxBackground_BLUE = 0x2c
LinuxBackground_FUCHSIA = 0x2d
LinuxBackground_CYAN = 0x2e
LinuxBackground_WHITE = 0x2f
)
/*
coding meaning
0 Terminal default settings (终端默认设置)
1 Highlight (高亮显示)
4 Use underline (使用下划线)
5 flashes (闪烁)
7 Highlighted (反白显示)
8 Invisible (不可见)
*/
/*
@param 1: background color
@param 2: foreground color
@param 3: content
*/
func LinuxColorPrint(bg int, fg int, str string) {
//SGR params x1b = 033
strFmt := fmt.Sprintf("\x1b[%dm\x1b[%dm%s\x1b[0m", bg, fg, str)
fmt.Println(strFmt)
}
/*
default background color: black
@param 1: foreground color
@param 2: content
*/
func LinuxDefaultBGPrint(fg int, str string) {
strFmt := fmt.Sprintf("\x1b[40m\x1b[%dm%s\x1b[0m", fg, str)
fmt.Println(strFmt)
}
/*
default background color: black
default foreground color: white
@param 1: content
*/
func LinuxDefaultColorPrint(str string) {
strFmt := fmt.Sprintf("\x1b[m%s\x1b[0m", str)
fmt.Println(strFmt)
}
Go
1
https://gitee.com/emmm_admin/xgameCommon.git
git@gitee.com:emmm_admin/xgameCommon.git
emmm_admin
xgameCommon
xgameCommon
v0.0.5

搜索帮助