- 修复 --help/-h/-?/--version 在交互模式下无响应的问题 - 新增 internal/logo/logo.go 统一管理logo展示 - 新增 build.sh 自动注入git版本号 - TUI头部与CLI使用统一logo模块 - 移除TUI头部的 [Ctrl+C 退出] 显示 - 统一版本号格式: ( v1.1.1-dirty )
80 lines
1.7 KiB
Go
80 lines
1.7 KiB
Go
package logo
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
var version string
|
|
|
|
func SetVersion(v string) { version = v }
|
|
|
|
func GetVersion() string { return version }
|
|
|
|
func GradientText(text string, startColor, endColor string) string {
|
|
startR, startG, startB := parseHexColor(startColor)
|
|
endR, endG, endB := parseHexColor(endColor)
|
|
|
|
lines := strings.Split(text, "\n")
|
|
if len(lines) == 0 {
|
|
return text
|
|
}
|
|
|
|
var result []string
|
|
for _, line := range lines {
|
|
if len(line) == 0 {
|
|
result = append(result, line)
|
|
continue
|
|
}
|
|
|
|
var coloredLine string
|
|
for i, char := range line {
|
|
ratio := float64(i) / float64(len(line)-1)
|
|
r := int(float64(startR) + float64(endR-startR)*ratio)
|
|
g := int(float64(startG) + float64(endG-startG)*ratio)
|
|
b := int(float64(startB) + float64(endB-startB)*ratio)
|
|
coloredLine += fmt.Sprintf("\033[38;2;%d;%d;%dm%s\033[0m", r, g, b, string(char))
|
|
}
|
|
result = append(result, coloredLine)
|
|
}
|
|
|
|
return strings.Join(result, "\n")
|
|
}
|
|
|
|
func parseHexColor(hex string) (int, int, int) {
|
|
hex = strings.TrimPrefix(hex, "#")
|
|
if len(hex) != 6 {
|
|
return 0, 0, 0
|
|
}
|
|
var r, g, b int
|
|
fmt.Sscanf(hex, "%02x%02x%02x", &r, &g, &b)
|
|
return r, g, b
|
|
}
|
|
|
|
func GetLogoPattern() string {
|
|
return " _ _ _____ _____ " + "\n" +
|
|
"( \\/ ( _ ( _ ) " + "\n" +
|
|
" \\ / )(_)( )(_)( " + "\n" +
|
|
" (__)(_____(_____("
|
|
}
|
|
|
|
func GetVersionSuffix() string {
|
|
v := GetVersion()
|
|
if v != "" {
|
|
return " (" + v + " )"
|
|
}
|
|
return " ( )"
|
|
}
|
|
|
|
func PrintLogoWithVersion() {
|
|
logoPattern := " _ _ _____ _____\n" +
|
|
"( \\/ ( _ ( _ )\n" +
|
|
" \\ / )(_)( )(_)( \n" +
|
|
" (__)(_____(_____("
|
|
|
|
patternWithVersion := logoPattern + GetVersionSuffix()
|
|
|
|
colored := GradientText(patternWithVersion, "#B413DC", "#00C8C8")
|
|
fmt.Println(colored)
|
|
}
|