tea.go

 1package bubbletea
 2
 3import (
 4	"smoothie/server/middleware"
 5
 6	tea "github.com/charmbracelet/bubbletea"
 7	"github.com/gliderlabs/ssh"
 8)
 9
10type BubbleTeaHandler func(ssh.Session) (tea.Model, []tea.ProgramOption)
11
12func Middleware(bth BubbleTeaHandler) middleware.Middleware {
13	return func(sh ssh.Handler) ssh.Handler {
14		return func(s ssh.Session) {
15			m, opts := bth(s)
16			if m != nil {
17				opts = append(opts, tea.WithInput(s), tea.WithOutput(s))
18				p := tea.NewProgram(m, opts...)
19				_ = p.Start()
20			}
21			sh(s)
22		}
23	}
24}