From e938b1c24a85df1d1092685d2808f186a4820a04 Mon Sep 17 00:00:00 2001 From: Toby Padilla Date: Fri, 30 Jul 2021 17:02:15 -0500 Subject: [PATCH] Move ProgramOptions to BubbleTeaHandler --- main.go | 3 +-- server/middleware/bubbletea/tea.go | 6 ++++-- tui/model.go | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 34c7c444bfef7f505bab53c414e76f5c83ffe084..a2cc4c953ff6da2861835f430dd3e3acdce97553 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,6 @@ import ( lm "smoothie/server/middleware/logging" "smoothie/tui" - tea "github.com/charmbracelet/bubbletea" "github.com/meowgorithm/babyenv" ) @@ -28,7 +27,7 @@ func main() { s, err := server.NewServer( cfg.Port, cfg.KeyPath, - bm.Middleware(tui.SessionHandler, tea.WithAltScreen()), + bm.Middleware(tui.SessionHandler), gm.Middleware(cfg.RepoPath, cfg.RepoAuthPath), lm.Middleware(), ) diff --git a/server/middleware/bubbletea/tea.go b/server/middleware/bubbletea/tea.go index cd80e8841d2867125f1e751583ee2c79ce2c3ef8..c234b13c8741cd1155b511e5a8f84ae0f19b90cc 100644 --- a/server/middleware/bubbletea/tea.go +++ b/server/middleware/bubbletea/tea.go @@ -7,10 +7,12 @@ import ( "github.com/gliderlabs/ssh" ) -func Middleware(bth func(ssh.Session) tea.Model, opts ...tea.ProgramOption) middleware.Middleware { +type BubbleTeaHandler func(ssh.Session) (tea.Model, []tea.ProgramOption) + +func Middleware(bth BubbleTeaHandler) middleware.Middleware { return func(sh ssh.Handler) ssh.Handler { return func(s ssh.Session) { - m := bth(s) + m, opts := bth(s) if m != nil { opts = append(opts, tea.WithInput(s), tea.WithOutput(s)) p := tea.NewProgram(m, opts...) diff --git a/tui/model.go b/tui/model.go index 5cc2ba86de05fd049030ac0628bc6b34973bb702..9ed9028a608a7fa2fea953a65cd5839309e2081c 100644 --- a/tui/model.go +++ b/tui/model.go @@ -24,15 +24,15 @@ func (e errMsg) Error() string { return e.err.Error() } -func SessionHandler(s ssh.Session) tea.Model { +func SessionHandler(s ssh.Session) (tea.Model, []tea.ProgramOption) { if len(s.Command()) == 0 { pty, changes, active := s.Pty() if !active { - return nil + return nil, nil } - return NewModel(pty.Window.Width, pty.Window.Height, changes) + return NewModel(pty.Window.Width, pty.Window.Height, changes), []tea.ProgramOption{tea.WithAltScreen()} } - return nil + return nil, nil } type Model struct {