1package tui
2
3import (
4 "fmt"
5
6 tea "github.com/charmbracelet/bubbletea"
7 "github.com/charmbracelet/soft-serve/internal/config"
8 "github.com/gliderlabs/ssh"
9)
10
11// SessionHandler handles the bubble tea session.
12func SessionHandler(cfg *config.Config) func(ssh.Session) (tea.Model, []tea.ProgramOption) {
13 return func(s ssh.Session) (tea.Model, []tea.ProgramOption) {
14 pty, _, active := s.Pty()
15 if !active {
16 fmt.Println("not active")
17 return nil, nil
18 }
19 cmd := s.Command()
20 scfg := &SessionConfig{Session: s}
21 switch len(cmd) {
22 case 0:
23 scfg.InitialRepo = ""
24 case 1:
25 scfg.InitialRepo = cmd[0]
26 }
27 scfg.Width = pty.Window.Width
28 scfg.Height = pty.Window.Height
29 if cfg.Cfg.Callbacks != nil {
30 cfg.Cfg.Callbacks.Tui("view")
31 }
32 return NewBubble(cfg, scfg), []tea.ProgramOption{
33 tea.WithAltScreen(),
34 tea.WithoutCatchPanics(),
35 }
36 }
37}