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

@@ -14,6 +14,7 @@ import (
"github.com/titor/fanyi/internal/cache"
"github.com/titor/fanyi/internal/config"
"github.com/titor/fanyi/internal/lang"
"github.com/titor/fanyi/internal/logo"
"github.com/titor/fanyi/internal/onboard"
"github.com/titor/fanyi/internal/provider"
"github.com/titor/fanyi/internal/translator"
@@ -25,6 +26,7 @@ var (
version = flag.Bool("version", false, "显示版本信息")
help = flag.Bool("help", false, "显示帮助信息")
h = flag.Bool("h", false, "显示帮助信息")
question = flag.Bool("?", false, "显示帮助信息")
langFlag = flag.String("lang", "", "目标语言代码(如 zh-CN, en-US, cn, en 等)")
langLong = flag.String("language", "", "目标语言代码(--lang的长格式")
configFile = flag.String("config", "", "配置文件路径")
@@ -38,8 +40,6 @@ var (
interactiveShort = flag.Bool("i", false, "启动交互式翻译界面(-i的短格式")
)
const versionString = "YOYO翻译工具 v1.1.0"
// isPipeInput 检测是否有管道输入
func isPipeInput() bool {
fileInfo, err := os.Stdin.Stat()
@@ -104,6 +104,17 @@ func main() {
return
}
if *help || *h || *question {
printHelp()
return
}
// 处理 -? 作为位置参数的情况
if flag.NArg() > 0 && (flag.Arg(0) == "-?" || flag.Arg(0) == "?") {
printHelp()
return
}
// 处理交互式模式
if *interactive || *interactiveShort || shouldStartInteractive() {
startInteractiveMode()
@@ -112,14 +123,8 @@ func main() {
// 处理管道输入情况
if isPipeInput() {
// 管道模式下,即使没有参数也继续执行
if *help || *h {
printHelp()
return
}
} else {
// 非管道模式下,没有参数则显示帮助
if *help || *h || flag.NArg() == 0 {
// 管道模式下,没有参数则显示帮助
if flag.NArg() == 0 {
printHelp()
return
}
@@ -372,12 +377,14 @@ func runCacheCommand(subcommand string) {
// printVersion 显示版本信息
func printVersion() {
fmt.Println(versionString)
logo.PrintLogoWithVersion()
}
// printHelp 显示帮助信息
func printHelp() {
fmt.Printf(`%s
logo.PrintLogoWithVersion()
fmt.Printf(`
使用方法:
yoyo [选项] <文本>
@@ -445,8 +452,8 @@ func printHelp() {
- 默认厂商: siliconflow
- 默认目标语言: zh-CN (简体中文)
更多信息请访问: https://github.com/titor/fanyi
`, versionString)
更多信息请访问: https://github.com/titor/fanyi
`)
}
// shouldStartInteractive 判断是否应该启动交互式模式