feat: 实现模块2 - TUI输入组件 (textinput)
This commit is contained in:
33
memory.md
33
memory.md
@@ -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
|
||||
```
|
||||
Reference in New Issue
Block a user