Diff
1diff --git a/main.go b/main.go
2index 34c7c444bfef7f505bab53c414e76f5c83ffe084..a2cc4c953ff6da2861835f430dd3e3acdce97553 100644
3--- a/main.go
4+++ b/main.go
5@@ -8,7 +8,6 @@ import (
6 lm "smoothie/server/middleware/logging"
7 "smoothie/tui"
8
9- tea "github.com/charmbracelet/bubbletea"
10 "github.com/meowgorithm/babyenv"
11 )
12
13@@ -28,7 +27,7 @@ func main() {
14 s, err := server.NewServer(
15 cfg.Port,
16 cfg.KeyPath,
17- bm.Middleware(tui.SessionHandler, tea.WithAltScreen()),
18+ bm.Middleware(tui.SessionHandler),
19 gm.Middleware(cfg.RepoPath, cfg.RepoAuthPath),
20 lm.Middleware(),
21 )
22diff --git a/server/middleware/bubbletea/tea.go b/server/middleware/bubbletea/tea.go
23index cd80e8841d2867125f1e751583ee2c79ce2c3ef8..c234b13c8741cd1155b511e5a8f84ae0f19b90cc 100644
24--- a/server/middleware/bubbletea/tea.go
25+++ b/server/middleware/bubbletea/tea.go
26@@ -7,10 +7,12 @@ import (
27 "github.com/gliderlabs/ssh"
28 )
29
30-func Middleware(bth func(ssh.Session) tea.Model, opts ...tea.ProgramOption) middleware.Middleware {
31+type BubbleTeaHandler func(ssh.Session) (tea.Model, []tea.ProgramOption)
32+
33+func Middleware(bth BubbleTeaHandler) middleware.Middleware {
34 return func(sh ssh.Handler) ssh.Handler {
35 return func(s ssh.Session) {
36- m := bth(s)
37+ m, opts := bth(s)
38 if m != nil {
39 opts = append(opts, tea.WithInput(s), tea.WithOutput(s))
40 p := tea.NewProgram(m, opts...)
41diff --git a/tui/model.go b/tui/model.go
42index 5cc2ba86de05fd049030ac0628bc6b34973bb702..9ed9028a608a7fa2fea953a65cd5839309e2081c 100644
43--- a/tui/model.go
44+++ b/tui/model.go
45@@ -24,15 +24,15 @@ func (e errMsg) Error() string {
46 return e.err.Error()
47 }
48
49-func SessionHandler(s ssh.Session) tea.Model {
50+func SessionHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) {
51 if len(s.Command()) == 0 {
52 pty, changes, active := s.Pty()
53 if !active {
54- return nil
55+ return nil, nil
56 }
57- return NewModel(pty.Window.Width, pty.Window.Height, changes)
58+ return NewModel(pty.Window.Width, pty.Window.Height, changes), []tea.ProgramOption{tea.WithAltScreen()}
59 }
60- return nil
61+ return nil, nil
62 }
63
64 type Model struct {