charmbracelet / charmbracelet/bubbletea

Running bubbletea apps inside vim gives bad output

Open
#797 1 comment 3 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
44.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Being experimenting with running bubbletea programs inside vim/neovim using `:!app`, here's what I've found:

# Problem 1: stdin and opening a tty

If you don't pass a `WithInput` option, bubbletea will fallback to `/dev/stdin`, which is OK, but then it'll try to open a new tty, which fails inside vim.

Passing `WithInput(nil)` fixes the issue.

## Problem 1.2: `WithInput(os.Stdin)`

If instead of a `nil` input, you pass `os.Stdin` directly, you get a even weirder error:

```
:!go run .
^[[?25lcould not run program: error creating cancelreader: add reader to epoll interest list
exit status 1

shell returned 1
```

# Problem 2: ansi escape codes in output

Ok, let's keep the `WithInput(nil)`, if you then run the program from within vim, you'll get ansi escape code sequences all over the place:

```
:!go run .
^[[?25l
/ Spinning...

h/l, ←/→: change spinner • q: exit
^[[0D^[[1A^[[1A^[[1A^[[2K^[[1A^[[0D^[[2K
- Spinning...
^[[1B^[[1B^[[0D^[[1A^[[1A^[[1A^[[2K^[[1A^[[0D^[[2K
\ Spinning...
^[[1B^[[1B^[[0D^[[1A^[[1A^[[1A^[[2K^[[1A^[[0D^[[2K
| Spinning...
^[[1B^[[1B^[[0D^[[1A^[[1A^[[1A^[[2K^[[1A^[[0D^[[2K
/ Spinning...
^[[1B^[[1B^[[0D^[[1A^[[1A^[[1A^[[2K^[[1A^[[0D^[[2K
```

To be honest, that seems to happen with other things too, e.g., fish shell:

```
:!echo (set_color --bold magenta) "Hello world"
^[[1m^[[35m Hello world

Press ENTER or type command to continue
```

---

# Footnotes

- Lipgloss examples seem to work properly
- Termenv examples also print the escape codes, so maybe the problem is there?
- I think the biggest real bugs here involve setting the input, not sure what the right behavior should be though

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.