feat: Logo模块化与渐变色统一

- 修复 --help/-h/-?/--version 在交互模式下无响应的问题
- 新增 internal/logo/logo.go 统一管理logo展示
- 新增 build.sh 自动注入git版本号
- TUI头部与CLI使用统一logo模块
- 移除TUI头部的 [Ctrl+C 退出] 显示
- 统一版本号格式: ( v1.1.1-dirty )
This commit is contained in:
2026-04-08 01:08:47 +08:00
parent 9acbc834a4
commit a9b7a69224
7 changed files with 237 additions and 67 deletions

View File

@@ -894,4 +894,45 @@ v2:
```go
p := tea.NewProgram(model{})
p.Run()
```
```
---
### Logo模块化设计
**决策**: 创建 `internal/logo/logo.go` 统一管理logoTUI和CLI共享
**原因**:
1. 避免代码重复TUI和CLI都需要显示logo
2. 统一渐变色方案:紫→青 (`#B413DC``#00C8C8`)
3. 统一版本号格式:` ( v1.x.x )`` ( )`
**实现**:
```go
// 导出函数供外部调用
func GradientText(text string, startColor, endColor string) string
func GetLogoPattern() string // ASCII art图案
func GetVersionSuffix() string // " (v1.x.x )" 或 " ( )"
func PrintLogoWithVersion() // 打印完整logo
```
**版本注入**:
```go
// 编译时通过 ldflags 注入
// -X packagepath.variable=value
go build -ldflags "-X github.com/titor/fanyi/internal/logo.version=${VERSION}" -o yoyo ./cmd/yoyo
```
### 终端颜色输出问题
**问题**: 在非TTY环境如管道ANSI转义序列可能显示为明文
**观察**:
- 使用 `script` 命令可以正确显示颜色
- `od -c` 检查输出包含正确的 `\033` 转义字符
- zsh 可能对某些颜色转义处理不同
**解决方案**:
- 使用 `GradientText` 函数逐字符应用渐变
- 每个字符后使用 `\033[0m` 重置
- 渐变使用 24-bit 颜色 `\033[38;2;R;G;Bm`