bubbletea
bubbletea copied to clipboard
Running programs in subshells
I just recently switched my project jumper from using tcell to bubbletea but I have run into some issues with ioctl.
Previously i was able to run my script in a sub command like cd $(jumper to)
. Now when i try that same command with bubbletea i get the the following error:
inappropriate ioctl for device
cd: string not in pwd: ^[[?25l^[[?1049h^[[0;0H^[[?1002l^[[?1003l^[[1;m❯^[[0m
Some searching in tcell led me to this https://github.com/gdamore/tcell/blob/7946eb8e8d8303b1ee1da909dcdebf448f0b5cb7/nonblock_unix.go#L25-L40
Seems as though bubbletea isn't waiting for the output to drain properly (if im understanding the tcell code correctly.)
Good catch and thanks for the report. I can reproduce this on my end. This absolutely something we'll need to fix. We'll keep this thread updated with progress.
I started digging into it to see if i could figure out how tcell is doing it. Can't promise I can figure out a fix since I don't have much free time anymore but if I can figure out a fix from tinkering around I'll open a PR.
@meowgorithm saw your comment on #228. That didn't fully resolve the issue for me in my program.
Running the program in a subshell no longer gives a ioctl error but instead renders nothing. Then on any keypress a panic ensues when restoring the terminal.
runtime/debug.Stack()
/usr/local/Cellar/go/1.17.6/libexec/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
/usr/local/Cellar/go/1.17.6/libexec/src/runtime/debug/stack.go:16 +0x19
github.com/charmbracelet/bubbletea.(*Program).StartReturningModel.func3()
/Users/mporter/go/pkg/mod/github.com/charmbracelet/[email protected]/tea.go:359 +0x95
panic({0x13a5680, 0x1714b10})
/usr/local/Cellar/go/1.17.6/libexec/src/runtime/panic.go:1047 +0x266
github.com/m-porter/jumper/internal/tui.(*model).moveCursorDown(...)
/Users/mporter/dev/mporter/jumper/internal/tui/tui.go:143
github.com/m-porter/jumper/internal/tui.(*model).Update(0xc0001101e0, {0x13cfd60, 0xc00030c000})
/Users/mporter/dev/mporter/jumper/internal/tui/tui.go:80 +0xd2
github.com/charmbracelet/bubbletea.(*Program).StartReturningModel(0xc000034080)
/Users/mporter/go/pkg/mod/github.com/charmbracelet/[email protected]/tea.go:547 +0x13f1
github.com/charmbracelet/bubbletea.(*Program).Start(...)
/Users/mporter/go/pkg/mod/github.com/charmbracelet/[email protected]/tea.go:556
github.com/m-porter/jumper/internal/tui.Run(0xd0)
/Users/mporter/dev/mporter/jumper/internal/tui/tui.go:186 +0xfa
github.com/m-porter/jumper/internal/cmd.ToCmd.func1(0xc000240280, {0x13fb0c2, 0x0, 0x0})
/Users/mporter/dev/mporter/jumper/internal/cmd/to.go:15 +0x25
github.com/spf13/cobra.(*Command).execute(0xc000240280, {0x17557b8, 0x0, 0x0})
/Users/mporter/go/pkg/mod/github.com/spf13/[email protected]/command.go:852 +0x60e
github.com/spf13/cobra.(*Command).ExecuteC(0xc000240000)
/Users/mporter/go/pkg/mod/github.com/spf13/[email protected]/command.go:960 +0x3ad
github.com/spf13/cobra.(*Command).Execute(...)
/Users/mporter/go/pkg/mod/github.com/spf13/[email protected]/command.go:897
main.main()
/Users/mporter/dev/mporter/jumper/main.go:15 +0x113
Caught panic: runtime error: invalid memory address or nil pointer dereference Restoring terminal...
To reproduce
git clone https://github.com/M-Porter/jumper.git
cd jumper
echo $(go run . to)
@M-Porter thanks for that info. This is definitely something that's not resolved yet and we're very keen to sort this one out. We'll keep this issue updated with progress.
for sure. i just figured any info along the way would help!
I'm very interested in this as well, and have been doing a bit of exploration with muesli's help. I wrote up a few proposals: https://gist.github.com/wesen/045b8ef7227ddd8a6951cd308e5d4634
This seems like a separate issue (that I didn't run into yet), but I might take a closer look, to see if it impacts my use case too.
@wesen I tested proposal 1 and i can use the program in a subshell now but there are still no colors output.
Hey @M-Porter, if I'm understanding your issue correctly you want to do something similar to https://github.com/charmbracelet/gum (running Bubble Tea programs and using their output) but running the program separately. They way that we got around this was by running the program on os.Stderr
and setting the Lip Gloss profile manually lipgloss.SetProfile(...)
which allows us to do things like:
vim $(gum filter)