charmbracelet / charmbracelet/bubbles

textinput cursor doesn't have background

Open
#897 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
8.9k
Forks
457
Avg merge
1d 18h
Merged PRs (30d)
5

Description

**Describe the bug**
After migrating to v2, I fixed one issue but introduced two (actually three) new ones. The cursor now has no background color when drawn without text.

![Image](https://github.com/user-attachments/assets/0d04baa5-2044-4ecf-b2ef-f327ee646204)

**Setup**
- OS Windows 10-11
- Shell Powershell
- Terminal Emulator Windows Terminal
- Terminal Multiplexer - none
- Locale en_US

**To Reproduce**
Just set a style with a background color for textinput.

**Source Code**
Here's how I initialize textinput
```go
func newTextinput(style lipgloss.Style, grayColor color.Color) textinput.Model {
input := textinput.New()
input.CharLimit = 255 // hello, windows!
input.SetWidth(0) // TODO: it's bugged right now, wait until it's fixed and clean up update then
styles := input.Styles()
styles.Focused.Text = style
styles.Focused.Placeholder = style.Foreground(grayColor)
styles.Focused.Suggestion = style.Foreground(grayColor)
styles.Focused.Prompt = style.Foreground(grayColor)

styles.Blurred.Text = style
styles.Blurred.Placeholder = style.Foreground(grayColor)
styles.Blurred.Suggestion = style.Foreground(grayColor)
styles.Blurred.Prompt = style.Foreground(grayColor)

styles.Cursor.Color = style.GetForeground()
styles.Cursor.Blink = true
input.SetStyles(styles)
return input
}
```
**Expected behavior**
It used to draw just fine in v1

**Screenshots**
It looks like this when there are multiple textinputs:
![Image](https://github.com/user-attachments/assets/b2aae43b-a068-4314-b601-1dec1ef65f46)

**Additional context**
Also, on my Windows 10 machine Alacritty looks completely broken now with v2, it was also fine before.
Image
It shows cursor (right-bottom corner) and Esc doesn't work. It's also messed up.

There is a pull request https://github.com/charmbracelet/bubbles/pull/892
But it changes the view(). In my opinion the issue is here
```go
// SetStyles sets the styles for the text input.
func (m *Model) SetStyles(s Styles) {
m.styles = s
m.updateVirtualCursorStyle()
}

// updateVirtualCursorStyle sets styling on the virtual cursor based on the
// textarea's style settings.
func (m *Model) updateVirtualCursorStyle() {
if !m.useVirtualCursor {
// Hide the virtual cursor if we're using a real cursor.
m.virtualCursor.SetMode(cursor.CursorHide)
return
}

m.virtualCursor.Style = lipgloss.NewStyle().Foreground(m.styles.Cursor.Color)

// By default, the blink speed of the cursor is set to a default
// internally.
if m.styles.Cursor.Blink {
if m.styles.Cursor.BlinkSpeed > 0 {
m.virtualCursor.BlinkSpeed = m.styles.Cursor.BlinkSpeed
}
m.virtualCursor.SetMode(cursor.CursorBlink)
return
}
m.virtualCursor.SetMode(cursor.CursorStatic)
}
```
`m.virtualCursor.Style = lipgloss.NewStyle().Foreground(m.styles.Cursor.Color)` creates a new style, that probably has black background. But I dunno, I haven't tried to fix it. I might be wrong.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.