Setting value with a style breakes textarea #708
-
Describe the bug I'm trying to set the textarea value to a string that has styles rendered. I expect the output to override the default styles, instead the textarea outputs the string escaped Setup
To Reproduce
Source Code package main
import (
// "fmt"
"log"
"github.com/charmbracelet/bubbles/textarea"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var textStyle = lipgloss.NewStyle().Padding(1, 2).Faint(true);
func main() {
p := tea.NewProgram(initialModel(), tea.WithAltScreen())
if _, err := p.Run(); err != nil {
log.Fatal(err)
}
}
type model struct {
textarea textarea.Model
}
func initialModel() model {
ti := textarea.New()
ti.CursorStart()
ti.Focus()
return model{
textarea: ti,
}
}
func (m model) Init() tea.Cmd {
return textarea.Blink
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd
var cmd tea.Cmd
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.Type {
case tea.KeyEsc:
if m.textarea.Focused() {
m.textarea.Blur()
}
case tea.KeyCtrlC:
return m, tea.Quit
case tea.KeyUp:
m.textarea.SetValue(textStyle.Render("Hello world"))
default:
if !m.textarea.Focused() {
cmd = m.textarea.Focus()
cmds = append(cmds, cmd)
}
}
}
m.textarea, cmd = m.textarea.Update(msg)
cmds = append(cmds, cmd)
return m, tea.Batch(cmds...)
}
func (m model) View() string {
return m.textarea.View()
} Expected behavior Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
After commenting out the code at Line 88 in 6079650 (pressing the Left Arrow key multiple times, causes the part of the text to be in And there's the ability to set some styles within the |
Beta Was this translation helpful? Give feedback.
-
Hey @ipsavitsky textarea doesn't support stylized text. It's meant to just be plain text. If you wanted to display some text and modify it, I would recommend using a viewport to display the text, then use textarea to edit the unstyled/plain text. You could switch between the two in your program if you wanted. Please let me know if that clarifies things here. If it's still unclear, feel free to ping me. I'm going to convert this to a discussion instead of an issue as it's not something we're planning to address as of right now. |
Beta Was this translation helpful? Give feedback.
Hey @ipsavitsky textarea doesn't support stylized text. It's meant to just be plain text. If you wanted to display some text and modify it, I would recommend using a viewport to display the text, then use textarea to edit the unstyled/plain text.
You could switch between the two in your program if you wanted.
Please let me know if that clarifies things here. If it's still unclear, feel free to ping me. I'm going to convert this to a discussion instead of an issue as it's not something we're planning to address as of right now.