-
Notifications
You must be signed in to change notification settings - Fork 837
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
Spawning editors #171
Comments
Hi! Your code's pretty close. As a rule, you'll want to move all long running code into a type editingFinished struct{}
func openEditor(app string, args ...string) tea.Cmd {
return func() tea.Msg {
cmd := exec.Command(app, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
_ = cmd.Run() // blocks until finished
return editingFinished{}
}
}
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.editMode {
return m, nil
}
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "e":
m.editMode = true
return m, tea.Batch(
tea.HideCursor,
openEditor(lookup([]string{"LLAMA_EDITOR", "EDITOR"}, "less"), filepath.Join(m.path, m.cursorFileName())),
)
}
case editingFinished:
m.editMode = false
return m, nil
}
// ...
} Really nice work on llama, by the way. We actually added And by all means, let us know if you have any more questions. |
Thanks a lot! 🔥 |
For some reason, this approach does not work. And from example, vim and tea outputs get messed up. Can't figure out why. Trying to implement it in llama. |
Saw your other issue. It's probably unrelated to the above approach and in the end (once we figure it out) you'll mostly likely need to move stuff back into a command (illustrated above) in order a trigger a repaint. |
I also have the same issue when trying to open a file to edit via vim and then back into the app, the output gets messed up even after triggering a command to cause a repaint |
Probably, the right approach will be to use PTY. |
I've looked into this one a little bit. No conclusions yet, but my hunch says we'll need to introduce some functionality into Bubble Tea (likely by way of
Here's an example program I've been testing with. @knipferrc and @antonmedv: if it's convenient, I'd love to see a screenshot of the garbled output you're describing after closing Vim. I'm not able to reproduce that on my end yet. |
I tried to integrate github.com/creack/pty but this is quite difficult, we can't just io.Copy, and need to get part of UI as a string. |
Hi everyone 👋, Just wanted to chime in and hopefully give some useful pointers. This discussion is quite similar to one in tcell, another TUI framework which is also written in Go and had the same issue with running subcommands. Long story short: tcell had a similar issue which was eventually fixed here. I wish I could be more helpful than just refer to the ticket (most of the implementation goes over my head), but I hope that the implementation can be useful for Bubble Tea. (Btw, Bubble Tea is really great, I have been eagerly awaiting for this subcommand feature to see of I can replace the current TUI in |
I successfully opened vim according to the example, but after vim exited, I received a keymsg: It looks like this button appears in the standard input after the execution of vim is complete; I don't know what caused it. @meowgorithm Do you have any suggestions? |
@mritd That appears to be an open brace ( |
I also wanted to provide some updates on this issue. We're narrowing this ticket to be specific to spawning editors from within Bubble Tea (versus any sub-process), because most other processes (both blocking and non-blocking) can be currently handled fine in a Anyway, this is something we'd like to officially support in Bubble Tea. There are essentially two things to tackle:
In the meantime, for those interested in spawning in-terminal editors like Vim (@antonmedv, @mritd, @knipferrc) I recommend taking a look at |
Hello, a few elements that might be helpful :) I tried to run your example program in several environments (all Linux based): With kitty (https://sw.kovidgoyal.net/kitty/)
With neovim in kitty (opening a term in neovim with :terminal, then running the example, so we have vi, vim or nvim in nvim)
It seems that the "swallowed" keys are interpreted by bubbletea. E.g. typing q at as your first key will sometimes lead to exiting the go program as soon as vi exits. Thank you for your work on the charm projects, they are very fun to use :) |
I've just posted a draft PR that adds While the PR is not ready to merge just yet, I'd love to hear your feedback: does it fix the swallowed keys issue and stdin crashes/errors for you? (it does for me) |
Yes, using the |
Thanks for the feedback! I'll clean this PR up a bit and we'll merge this soon! |
@muesli has there been any progress on this front? I'd love to use bubbletea in a project I'm speccing out right now, but this would be a blocking issue. Thanks! |
Hey everyone! This is now available in |
Thanks a lot for your awesome library! |
Hi,
Thanks for the awesome project!
Question: how to properly start subcommand with reuse of Stdout/Stdin?
I'm doing it like so:
https://github.com/antonmedv/llama/blob/58c042eb06a5a661a1388beb4ac09cedf2764ad0/main.go#L183-L190
But what to do if a redraw is needed after cmd exits? And is there a better way to halt the program until cmd is exited?
Thanks.
Originally posted by @antonmedv in #170
The text was updated successfully, but these errors were encountered: