feat: 实现模块2 - TUI输入组件 (textinput)

This commit is contained in:
2026-04-06 05:10:00 +08:00
parent 1787464f52
commit 6f872ff285
4 changed files with 112 additions and 6 deletions

View File

@@ -586,4 +586,35 @@ func NewApp(cfg, translator) *tea.Program {
### main.go集成注意
- 版本检查(--version)需要在interactive模式检查之前
- 避免interactive模式在非TTY环境启动
- Run()需要两个返回值: `_, err := app.Run()`
- Run()需要两个返回值: `_, err := app.Run()`
### TextInput组件使用
```go
import "github.com/charmbracelet/bubbles/textinput"
// model中添加字段
type model struct {
textInput textinput.Model
}
// 初始化
ti := textinput.New()
ti.Placeholder = "输入文本..."
ti.Focus() // 获取焦点
ti.Prompt = "> " // 提示符
// Update中处理
m.textInput, cmd = m.textInput.Update(msg)
// View中显示
m.textInput.View()
```
### Lipgloss样式定义
```go
var style = lipgloss.NewStyle().
Foreground(lipgloss.Color("#FAFAFA")).
Background(lipgloss.Color("#1A1A2E"))
ti.TextStyle = style // 应用到textinput
```