package tui import ( "github.com/charmbracelet/bubbles/textinput" "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/titor/fanyi/internal/config" "github.com/titor/fanyi/internal/translator" ) type model struct { config *config.Config translator *translator.Translator textInput textinput.Model } var ( inputStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("#FAFAFA")). Background(lipgloss.Color("#1A1A2E")) focusedStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("#FAFAFA")). Background(lipgloss.Color("#16213E")) ) func NewApp(cfg *config.Config, t *translator.Translator) *tea.Program { ti := textinput.New() ti.Placeholder = "输入要翻译的文本..." ti.Focus() ti.Prompt = "> " ti.TextStyle = inputStyle return tea.NewProgram(model{ config: cfg, translator: t, textInput: ti, }) } func (m model) Init() tea.Cmd { return nil } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { case tea.KeyMsg: switch msg.Type { case tea.KeyEnter: // 回车键处理,后续模块会添加翻译逻辑 case tea.KeyCtrlC, tea.KeyEsc: return m, tea.Quit } } m.textInput, cmd = m.textInput.Update(msg) return m, cmd } func (m model) View() string { return "\n" + " YOYO翻译\n" + " ─────────────────────\n\n" + " " + m.textInput.View() + "\n\n" + " 按 Ctrl+C 退出\n" }