m.textarea, tiCmd = m.textarea.Update(msg)
m.viewport, vpCmd = m.viewport.Update(msg)
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.Type {
case tea.KeyCtrlC, tea.KeyEsc:
fmt.Println(m.textarea.Value())
return m, tea.Quit
case tea.KeyEnter:
m.messages = append(m.messages, m.senderStyle.Render("You: ")+m.textarea.Value())
m.viewport.SetContent(strings.Join(m.messages, "\n"))
m.textarea.Reset()
m.viewport.GotoBottom()
}
// We handle errors just like any other message
case errMsg:
m.err = msg
return m, nil
}
return m, tea.Batch(tiCmd, vpCmd)
Describe the bug
textarea.Placeholder
cannot display the first Chinese character properlySetup
To Reproduce
https://github.com/charmbracelet/bubbletea/blob/master/examples/chat/main.go
to
go run main.go
┃ è��入消息...
┃
package main
// A simple program demonstrating the text area component from the Bubbles // component library.
import ( "fmt" "log" "strings"
)
func main() { p := tea.NewProgram(initialModel())
}
type ( errMsg error )
type model struct { viewport viewport.Model messages []string textarea textarea.Model senderStyle lipgloss.Style err error }
func initialModel() model { ta := textarea.New() ta.Placeholder = "输入消息..." ta.Focus()
Type a message and press Enter to send.`)
}
func (m model) Init() tea.Cmd { return textarea.Blink }
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var ( tiCmd tea.Cmd vpCmd tea.Cmd )
}
func (m model) View() string { return fmt.Sprintf( "%s\n\n%s", m.viewport.View(), m.textarea.View(), ) + "\n\n" }