Change summary
main.go | 3 +--
server/middleware/bubbletea/tea.go | 6 ++++--
tui/model.go | 8 ++++----
3 files changed, 9 insertions(+), 8 deletions(-)
Detailed changes
@@ -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(),
)
@@ -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...)
@@ -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 {