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