mirror of
https://github.com/maaslalani/slides.git
synced 2026-04-23 03:00:33 -04:00
32 lines
799 B
Go
32 lines
799 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/ssh"
|
|
"github.com/charmbracelet/wish"
|
|
bm "github.com/charmbracelet/wish/bubbletea"
|
|
"github.com/muesli/termenv"
|
|
)
|
|
|
|
func slidesMiddleware(srv *Server) wish.Middleware {
|
|
newProg := func(m tea.Model, opts ...tea.ProgramOption) *tea.Program {
|
|
p := tea.NewProgram(m, opts...)
|
|
return p
|
|
}
|
|
teaHandler := func(s ssh.Session) *tea.Program {
|
|
_, _, active := s.Pty()
|
|
if !active {
|
|
fmt.Println("no active terminal, skipping")
|
|
err := s.Exit(1)
|
|
if err != nil {
|
|
fmt.Println("Error exiting session")
|
|
}
|
|
return nil
|
|
}
|
|
return newProg(srv.presentation, tea.WithInput(s), tea.WithOutput(s), tea.WithAltScreen())
|
|
}
|
|
return bm.MiddlewareWithProgramHandler(teaHandler, termenv.ANSI256)
|
|
}
|