-
Notifications
You must be signed in to change notification settings - Fork 73
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
Bubbletea ExecProcess within a wish session #196
Comments
Fixes #107 This is a big change that does the following: - replaces the bespoke exec implementation with an impl inspired from the nomad cli, using the client directly - add a wander exec command - therefore tls is supported - improves general exec experience (can move cursor, does not strip ansi escape sequences, etc) - BREAKAGE: exec with wander serve breaks. Unfortunately with this impl, tea.ExecProcess is used, which is currently charmbracelet/wish#196
Hey, thanks for the issue! Opened #197, if you can try it out. PS: it'll not work on windows :| |
Hi @caarlos0 , thanks so much for hopping on this! It almost works perfectly, but I'm finding that if I want to return to the application that shows "Press 'e' to edit" after exiting vim, I can't. E.g. in the example your PR is adding, comment out: case VimFinishedMsg:
//if msg.err != nil {
// m.err = msg.err
// return m, tea.Quit
//}
} Then run the app, enter and exit vim, then terminal becomes non responsive |
no problem! to do that, you'll need to change it to also updated the PR if you wanna check it out |
unfortunately i'm still getting the terminal freezing on 2023-12-04_13-47-32.mp4 |
ah, I see what's going on: case VimFinishedMsg:
m.err = msg.err
return m, nil this should fix it.. |
no dice :/ demo with updated version: 2023-12-04_18-38-24.mp4 |
I'm unable to repro this... are you running the full example from #197? If so, which terminal and contents of |
Thanks for trying! I am also unable to repro in a docker container as follows (it works there): dockerized :wq returns without hanging:
Here are details of my environment where it doesn't work:
I've tried various things to make it work in my environment, but none have worked yet, including:
|
Does it work if you run with other editor, for example, nano? |
Another data point: running
successfully connects to the app hosted outside docker from inside docker, but still hangs on exit. Was wondering if maybe it was the version/configuration of |
Thanks! I'll try to repro this again later today 🙏 |
ok, on macos I can repro it all the time added this: case VimFinishedMsg:
m.err = msg.err
if m.err != nil {
log.Error("vim finished", "error", m.err)
}
return m, nil and got the actual issue:
now... why this happens, I dunno yet cc/ @aymanbagabas |
Digging into this using this diff on top of the example from #197, I was able to run Vim fine. However here, I believe both Bubble Tea and Vim are trying to acquire the terminal resulting in this error. When you run diff --git a/examples/wish-exec/main.go b/examples/wish-exec/main.go
index 3df70cd2d250..9ebc06446593 100644
--- a/examples/wish-exec/main.go
+++ b/examples/wish-exec/main.go
@@ -16,7 +16,6 @@ import (
"github.com/charmbracelet/log"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
- bm "github.com/charmbracelet/wish/bubbletea"
lm "github.com/charmbracelet/wish/logging"
)
@@ -30,7 +29,8 @@ func main() {
wish.WithAddress(fmt.Sprintf("%s:%d", host, port)),
ssh.AllocatePty(),
wish.WithMiddleware(
- bm.Middleware(teaHandler),
+ // bm.Middleware(teaHandler),
+ myHandler,
lm.Middleware(),
),
)
@@ -57,6 +57,21 @@ func main() {
}
}
+func myHandler(sh ssh.Handler) ssh.Handler {
+ return func(s ssh.Session) {
+ ppty, _, active := s.Pty()
+ if !active {
+ wish.Fatalln(s, "no active terminal, skipping")
+ return
+ }
+ c := ppty.Pty.Command("vim", "file.txt")
+ if err := c.Run(); err != nil {
+ wish.Fatalln(s, "vim failed", err)
+ return
+ }
+ }
+}
+
func teaHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) {
_, _, active := s.Pty()
if !active {
@@ -94,6 +109,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case VimFinishedMsg:
m.err = msg.err
+ if m.err != nil {
+ log.Error("vim finished", "error", m.err)
+ }
return m, nil
}
|
yep, that was my conclusion too... although for some reason I can't repro the issue on Linux, only on macOS. Maybe we could provide some sort of helper to do that? |
@caarlos0 and @aymanbagabas , let me know if there are any actions I can take to help validate the ideas of a fix here. Thanks for your help so far! |
Gentle bump on this - do y'all think you might plausibly get to a fix here sometime this month? If not I'll release v1.0 of my app anyway with a caveat about slightly limited functionality when using via the ssh app! |
Windows of course, (basically) doesn't have a TTY, but they sort-of recently got a PTY. ConPTY may be able suffice, maybe one can spawn a conpty like in #197 but I don't know the details. Leaving this note just in case someone else investigates.
|
unlikely, I haven't figured out how to fix this on macOS yet. since this will be breaking change, we'll also need to plan it properly 🙏 |
Hey, it works! Thanks so much @caarlos0 ! |
I have a bubble tea application where users can invoke an ExecProcess command to do something like enter
vim
. When I host the application using wish, the execprocess functionality breaks. For example:If I don't run this with wish, e.g. replace
main
with the following contents:Then the exec process works fine.
Any ideas on if and how this might be possible to fix?
The text was updated successfully, but these errors were encountered: