feat: 实现模块5 - TUI快捷键系统 (Ctrl+L清空/Ctrl+T切换语言)

This commit is contained in:
2026-04-06 05:15:24 +08:00
parent aefa0e8799
commit 8c6b08cec8
4 changed files with 54 additions and 5 deletions

View File

@@ -29,6 +29,7 @@
- [x] 模块2: 输入组件 ✅ 已完成
- [x] 模块3: 翻译显示区 ✅ 已完成
- [x] 模块4: 状态栏/主题 ✅ 已完成
- [x] 模块5: 快捷键系统 ✅ 已完成
## TUI界面实现计划 (v0.6.0)
| 步骤 | 模块 | 内容 | 状态 |
@@ -37,7 +38,7 @@
| 2 | 输入组件 | 文本输入框、光标、基础编辑 | ✅ 已完成 |
| 3 | 翻译显示区 | 结果展示、格式化、滚动 | ✅ 已完成 |
| 4 | 状态栏/主题 | 底部状态栏、语言选择、主题配色 | ✅ 已完成 |
| 5 | 快捷键系统 | 退出、清空、切换语言等 | ⏳ 待实现 |
| 5 | 快捷键系统 | 退出、清空、切换语言等 | ✅ 已完成 |
| 6 | 集成翻译 | 对接现有Translator、加载动画 | ⏳ 待实现 |
## 待修复BUG
@@ -54,7 +55,7 @@
- ✅ 模块2: 输入组件 - textinput组件、基础输入处理
- ✅ 模块3: 翻译显示区 - 结果显示区域、样式定义
- ✅ 模块4: 状态栏/主题 - 底部状态栏、语言显示、配色完善
- 模块5: 快捷键系统 - 待实现
- 模块5: 快捷键系统 - Ctrl+L清空、Ctrl+T切换语言
- ⏳ 模块6: 集成翻译 - 待实现
**技术实现**:
@@ -67,7 +68,7 @@
- [TUI界面模块拆分计划](taolun.md#2026-04-06-1000-版本-060---tui界面模块拆分计划)
**下一步**:
- 实现模块5: 快捷键系统
- 实现模块6: 集成翻译
---

View File

@@ -14,6 +14,7 @@ type model struct {
textInput textinput.Model
result string
targetLang string
langIndex int
}
var (
@@ -37,8 +38,12 @@ var (
langStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#FBBF24")).
Bold(true)
keyStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#60A5FA"))
)
var supportedLangs = []string{"zh-CN", "en-US", "ja", "ko", "zh-TW", "es", "fr", "de"}
func NewApp(cfg *config.Config, t *translator.Translator) *tea.Program {
targetLang := "zh-CN"
if cfg != nil && cfg.DefaultTargetLang != "" {
@@ -71,7 +76,19 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.Type {
case tea.KeyEnter:
// 回车键处理,后续模块会添加翻译逻辑
case tea.KeyCtrlC, tea.KeyEsc:
case tea.KeyCtrlC:
return m, tea.Quit
case tea.KeyCtrlL:
// Ctrl+L: 清空输入和结果
m.textInput.SetValue("")
m.result = ""
return m, nil
case tea.KeyCtrlT:
// Ctrl+T: 切换语言
m.langIndex = (m.langIndex + 1) % len(supportedLangs)
m.targetLang = supportedLangs[m.langIndex]
return m, nil
case tea.KeyEsc:
return m, tea.Quit
}
}
@@ -82,7 +99,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m model) View() string {
resultBox := m.renderResult()
helpText := helpStyle.Render("\n Ctrl+C 退出 · Enter 翻译")
helpText := helpStyle.Render("\n " +
keyStyle.Render("Ctrl+L") + " 清空 " +
keyStyle.Render("Ctrl+T") + " 切换语言 " +
keyStyle.Render("Enter") + " 翻译 " +
keyStyle.Render("Ctrl+C") + " 退出")
return "\n" +
" " + headerStyle.Render("YOYO翻译") + "\n" +

View File

@@ -621,6 +621,8 @@ var (
Background(lipgloss.Color("#0D1B2A"))
helpStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#888888"))
keyStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#60A5FA"))
)
```

View File

@@ -518,5 +518,30 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
**下一步**: 实现模块5: 快捷键系统
**关联文档**:
- [changelog.md#0.6.0](changelog.md#060)
---
### [2026-04-06 12:30] 版本 0.6.0 - 模块5: 快捷键系统 (已完成)
**原因**: 添加键盘快捷键提升用户体验
**分析**:
- 需要常用操作快捷键
- 需要清晰显示快捷键提示
**解决方案**:
1. 添加Ctrl+L: 清空输入和结果
2. 添加Ctrl+T: 循环切换语言
3. 添加keyStyle样式高亮快捷键
4. 更新帮助提示显示所有快捷键
**快捷键列表**:
- `Ctrl+L`: 清空输入框和翻译结果
- `Ctrl+T`: 循环切换目标语言 (zh-CN→en-US→ja→ko→...)
- `Ctrl+C`/`Esc`: 退出程序
- `Enter`: 翻译 (后续模块实现)
**下一步**: 实现模块6: 集成翻译
**关联文档**:
- [changelog.md#0.6.0](changelog.md#060)