Skip to content

Commit

Permalink
Pass ProgramOptions to Bubble Tea middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Padilla committed Jul 30, 2021
1 parent cf5a2ed commit 541e994
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"smoothie/tui"

tea "github.com/charmbracelet/bubbletea"
"github.com/meowgorithm/babyenv"
)

Expand All @@ -17,7 +18,8 @@ func main() {
if err != nil {
panic(err)
}
s, err := NewServer(cfg.Port, cfg.KeyPath, LoggingMiddleware(), BubbleTeaMiddleware(tui.SessionHandler))
btm := BubbleTeaMiddleware(tui.SessionHandler, tea.WithAltScreen())
s, err := NewServer(cfg.Port, cfg.KeyPath, LoggingMiddleware(), btm)
if err != nil {
panic(err)
}
Expand Down
5 changes: 3 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ func LoggingMiddleware() Middleware {
}
}

func BubbleTeaMiddleware(bth func(ssh.Session) tea.Model) Middleware {
func BubbleTeaMiddleware(bth func(ssh.Session) tea.Model, opts ...tea.ProgramOption) Middleware {
return func(sh ssh.Handler) ssh.Handler {
return func(s ssh.Session) {
m := bth(s)
if m != nil {
p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithInput(s), tea.WithOutput(s))
opts = append(opts, tea.WithInput(s), tea.WithOutput(s))
p := tea.NewProgram(m, opts...)
err := p.Start()
if err != nil {
log.Printf("%s error %v: %s\n", s.RemoteAddr().String(), s.Command(), err)
Expand Down

0 comments on commit 541e994

Please sign in to comment.