mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 02:04:09 +00:00
feat : added textcolor
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// 前景 背景 颜色
|
||||
// ---------------------------------------
|
||||
// 30 40 黑色
|
||||
// 31 41 红色
|
||||
// 32 42 绿色
|
||||
// 33 43 黄色
|
||||
// 34 44 蓝色
|
||||
// 35 45 紫红色
|
||||
// 36 46 青蓝色
|
||||
// 37 47 白色
|
||||
//
|
||||
// 代码 意义
|
||||
// -------------------------
|
||||
// 0 终端默认设置
|
||||
// 1 高亮显示
|
||||
// 4 使用下划线
|
||||
// 5 闪烁
|
||||
// 7 反白显示
|
||||
// 8 不可见
|
||||
|
||||
const (
|
||||
TextBlack = iota + 30
|
||||
TextRed
|
||||
TextGreen
|
||||
TextYellow
|
||||
TextBlue
|
||||
TextMagenta
|
||||
TextCyan
|
||||
TextWhite
|
||||
)
|
||||
|
||||
func Black(msg string) string {
|
||||
return SetColor(msg, 0, 0, TextBlack)
|
||||
}
|
||||
|
||||
func Red(msg string) string {
|
||||
return SetColor(msg, 0, 0, TextRed)
|
||||
}
|
||||
|
||||
func Green(msg string) string {
|
||||
return SetColor(msg, 0, 0, TextGreen)
|
||||
}
|
||||
|
||||
func Yellow(msg string) string {
|
||||
return SetColor(msg, 0, 0, TextYellow)
|
||||
}
|
||||
|
||||
func Blue(msg string) string {
|
||||
return SetColor(msg, 0, 0, TextBlue)
|
||||
}
|
||||
|
||||
func Magenta(msg string) string {
|
||||
return SetColor(msg, 0, 0, TextMagenta)
|
||||
}
|
||||
|
||||
func Cyan(msg string) string {
|
||||
return SetColor(msg, 0, 0, TextCyan)
|
||||
}
|
||||
|
||||
func White(msg string) string {
|
||||
return SetColor(msg, 0, 0, TextWhite)
|
||||
}
|
||||
|
||||
func SetColor(msg string, conf, bg, text int) string {
|
||||
return fmt.Sprintf("%c[%d;%d;%dm%s%c[0m", 0x1B, conf, bg, text, msg, 0x1B)
|
||||
}
|
||||
Reference in New Issue
Block a user