feat: 实现模块5 - TUI快捷键系统 (Ctrl+L清空/Ctrl+T切换语言)
This commit is contained in:
@@ -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" +
|
||||
|
||||
Reference in New Issue
Block a user