1package server
2
3import (
4 "fmt"
5
6 "github.com/aymanbagabas/go-osc52"
7 tea "github.com/charmbracelet/bubbletea"
8 appCfg "github.com/charmbracelet/soft-serve/config"
9 "github.com/charmbracelet/soft-serve/ui"
10 "github.com/charmbracelet/soft-serve/ui/common"
11 "github.com/charmbracelet/soft-serve/ui/keymap"
12 "github.com/charmbracelet/soft-serve/ui/styles"
13 bm "github.com/charmbracelet/wish/bubbletea"
14 "github.com/gliderlabs/ssh"
15)
16
17// SessionHandler is the soft-serve bubbletea ssh session handler.
18func SessionHandler(ac *appCfg.Config) bm.ProgramHandler {
19 return func(s ssh.Session) *tea.Program {
20 pty, _, active := s.Pty()
21 if !active {
22 return nil
23 }
24 cmd := s.Command()
25 initialRepo := ""
26 if len(cmd) == 1 {
27 initialRepo = cmd[0]
28 }
29 if ac.Cfg.Callbacks != nil {
30 ac.Cfg.Callbacks.Tui("new session")
31 }
32 envs := s.Environ()
33 envs = append(envs, fmt.Sprintf("TERM=%s", pty.Term))
34 output := osc52.NewOutput(s, envs)
35 c := common.Common{
36 Copy: output,
37 Styles: styles.DefaultStyles(),
38 KeyMap: keymap.DefaultKeyMap(),
39 Width: pty.Window.Width,
40 Height: pty.Window.Height,
41 }
42 m := ui.New(
43 ac,
44 s,
45 c,
46 initialRepo,
47 )
48 p := tea.NewProgram(m,
49 tea.WithInput(s),
50 tea.WithOutput(s),
51 tea.WithAltScreen(),
52 tea.WithoutCatchPanics(),
53 tea.WithMouseCellMotion(),
54 )
55 return p
56 }
57}