How to safely Exec any (non bubbletea) programs but maintain rendering #250
-
Hey there! First off, I recently found the charm eco system and I'm blown away and can't believe I didnt find this sooner. As a learning exercise I built a little Groc API based chat based on the https://github.com/charmbracelet/wish/blob/main/examples/multichat/main.go example and that was working well. I then found https://github.com/charmbracelet/mods which is exactly what I want in my daily flow, with the exception of accessing through SSH so I dont have to install mods on all my machines and I can centralize my settings in my home server. This works fairly well and I have a working example here! https://git.sr.ht/~zachr/mossh I wanted this to work in 2 ways:
While this works, as you can see from the screenshot all formatting/styling/lipgloss coming from mods isn't applied. I suspect this is because for However with option 2, in order to automatically pass the commands as args to mods I had to use a custom middleware as you can see here in my sample code:
So my question is this, is it possible to maintain the bubbletea formatting from an application installed on the SSH host (mods) when using I've spent quite some time looking at the examples and source code but I can't quite figure out where I'm going wrong. Any suggestions/tips or am I missing something obvious? Here is an example of what mods returns with a similar prompt directly and not through my wish server: Notice the pretty colors. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey, I believe that if you use wish.Command will create a PTY and run the command within it. That said, you can probably remove the that custom handler entirely, you just need to ssh -t -p 23234 localhost -- hello world Hope that helps. diff --git a/main.go b/main.go
index ed80a5f..0642607 100644
--- a/main.go
+++ b/main.go
@@ -5,7 +5,6 @@ import (
"errors"
"net"
"os"
- "os/exec"
"os/signal"
"syscall"
"time"
@@ -48,26 +47,6 @@ func main() {
}, []tea.ProgramOption{tea.WithAltScreen()}
}),
activeterm.Middleware(),
- func(next ssh.Handler) ssh.Handler {
- return func(sess ssh.Session) {
- // todo: figure out why the renderer wont work through ssh
- // renderer := bubbletea.MakeRenderer(sess)
-
- if len(sess.Command()) > 0 {
- // commands or args provided pass it to mods
- mods := exec.Command("mods", sess.Command()...)
- mods.Stdout = sess
- mods.Stderr = sess.Stderr()
-
- mods.Run()
-
- _ = sess.Exit(1)
- }
-
- next(sess)
- }
- },
-
logging.Middleware(),
),
) |
Beta Was this translation helpful? Give feedback.
-
omg i knew it was something silly. Thats amazing, thank you!! Love this toolset, thanks for all you do. |
Beta Was this translation helpful? Give feedback.
Hey, I believe that if you use
wish.Command
it should work.wish.Command will create a PTY and run the command within it.
That said, you can probably remove the that custom handler entirely, you just need to
ssh -t
(to request a tty) and then the original bubbletea handler will do the trick :)Hope that helps.