O_O
This commit is contained in:
45
internal/server.go
Normal file
45
internal/server.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/ssh"
|
||||
"github.com/charmbracelet/wish"
|
||||
lm "github.com/charmbracelet/wish/logging"
|
||||
)
|
||||
|
||||
func NewServer(host string, port int) (*ssh.Server, error) {
|
||||
srv, err := wish.NewServer(
|
||||
wish.WithAddress(fmt.Sprintf("%s:%d", host, port)),
|
||||
wish.WithHostKeyPath(".ssh/term_info_ed25519"),
|
||||
wish.WithPublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) bool {
|
||||
return true
|
||||
}),
|
||||
wish.WithMiddleware(
|
||||
appMiddleware,
|
||||
lm.Middleware(),
|
||||
),
|
||||
)
|
||||
return srv, err
|
||||
}
|
||||
|
||||
func appMiddleware(sh ssh.Handler) ssh.Handler {
|
||||
return func(s ssh.Session) {
|
||||
_, _, active := s.Pty()
|
||||
if !active {
|
||||
wish.Fatalln(s, "no active terminal, skipping")
|
||||
return
|
||||
}
|
||||
|
||||
m := initialModel(s)
|
||||
p := tea.NewProgram(m, tea.WithInput(s), tea.WithOutput(s), tea.WithAltScreen())
|
||||
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Println("Error running program:", err)
|
||||
}
|
||||
|
||||
updates.unsubscribe(m.updateChan)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user