Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running programs in subshells #206

Closed
M-Porter opened this issue Jan 28, 2022 · 8 comments
Closed

Running programs in subshells #206

M-Porter opened this issue Jan 28, 2022 · 8 comments
Labels
enhancement New feature or request

Comments

@M-Porter
Copy link

M-Porter commented Jan 28, 2022

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.)

@meowgorithm meowgorithm added the bug Something isn't working label Jan 28, 2022
@meowgorithm meowgorithm changed the title inappropriate ioctl for device Error running programs in subshells Jan 28, 2022
@meowgorithm
Copy link
Member

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.

@M-Porter
Copy link
Author

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.

@M-Porter
Copy link
Author

M-Porter commented Feb 18, 2022

@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/bubbletea@v0.20.0/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/bubbletea@v0.20.0/tea.go:547 +0x13f1
github.com/charmbracelet/bubbletea.(*Program).Start(...)
	/Users/mporter/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.20.0/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/cobra@v1.1.3/command.go:852 +0x60e
github.com/spf13/cobra.(*Command).ExecuteC(0xc000240000)
	/Users/mporter/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:960 +0x3ad
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/mporter/go/pkg/mod/github.com/spf13/cobra@v1.1.3/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)

@meowgorithm
Copy link
Member

@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.

@M-Porter
Copy link
Author

for sure. i just figured any info along the way would help!

@meowgorithm meowgorithm added enhancement New feature or request and removed bug Something isn't working labels Mar 18, 2022
@meowgorithm meowgorithm changed the title Error running programs in subshells Running programs in subshells Mar 18, 2022
@wesen
Copy link

wesen commented Mar 18, 2022

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.

@M-Porter
Copy link
Author

@wesen I tested proposal 1 and i can use the program in a subshell now but there are still no colors output.

@maaslalani
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants