charmbracelet / charmbracelet/bubbles
Spinner title has no space before it for non-Dots spinner types
- Dominant language
- Go
- Stars
- 8.9k
- Forks
- 457
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 5
Description
**Describe the bug**
When the spinner uses any type other than `Dots`, there is no space between the spinner glyph and the title. The title is printed right after the glyph, for example `|Loading` instead of `| Loading`.
The default `Dots` type looks correct only by accident: each of its frames already ends with a space. The other types do not end with a space, so the title sticks to the glyph. This affects `Line`, `MiniDot`, `Jump`, `Pulse`, `Points`, `Globe`, `Moon`, `Monkey`, `Meter`, `Hamburger`, and `Ellipsis`.
The cause is in `Spinner.View()`, which joins the glyph and the title with no separator:
```go
func (s *Spinner) View() string {
styles := s.theme.Theme(s.hasDarkBg)
s.spinner.Style = styles.Spinner
var title string
if s.title != "" {
title = styles.Title.Render(s.title)
}
return s.spinner.View() + title
}
```
So the spacing depends on whether the frame string ends with a space, which is not true for most types.
**Setup**
- OS: NixOS (Linux 6.18.33)
- Shell: zsh 5.9
- Terminal Emulator: Ghostty
- Terminal Multiplexer: none
- Locale: en_US.UTF-8
- huh version: v2.0.3
- Go version: 1.26.3
**To Reproduce**
Steps to reproduce the behavior:
1. Create a spinner with a non-default type, for example `spinner.Line`.
2. Set a title, for example "Loading".
3. Run it in a real terminal.
4. See the title printed with no space after the glyph, like `|Loading`.
**Source Code**
```go
package main
import (
"time"
"charm.land/huh/v2/spinner"
)
func main() {
// Try spinner.Line (no trailing space in its frames).
// The output looks like "|Loading", "/Loading", and so on.
_ = spinner.New().
Title("Loading").
Type(spinner.Line).
Action(func() { time.Sleep(2 * time.Second) }).
Run()
// With spinner.Dots the output looks fine ("dots Loading")
// only because the Dots frames end with a space.
}
```
**Expected behavior**
There should be a single space between the spinner glyph and the title for every spinner type, the same as the default `Dots` type. For example, `Line` should render `| Loading`, not `|Loading`.
**Screenshots**
I can add a screenshot if needed.
**Additional context**
I found this while building a CLI on top of huh. A safe fix is to add one space between the glyph and the title only when the glyph does not already end with whitespace, so the `Dots` type does not get a double space.
I am interested in fixing this. If the approach above sounds good to you, I am happy to open a pull request with a test that checks the spacing for a non-`Dots` type such as `Line`.
Contributor guide
Assessment
This issue has not been assessed yet.