repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

pico / tui
Eric Bower · 16 May 24

mdw.go

 1package tui
 2
 3import (
 4	tea "github.com/charmbracelet/bubbletea"
 5	"github.com/charmbracelet/ssh"
 6	bm "github.com/charmbracelet/wish/bubbletea"
 7	"github.com/picosh/pico/db/postgres"
 8	"github.com/picosh/pico/shared"
 9	"github.com/picosh/pico/tui/common"
10)
11
12func CmsMiddleware(cfg *shared.ConfigSite) bm.Handler {
13	return func(sesh ssh.Session) (tea.Model, []tea.ProgramOption) {
14		logger := cfg.Logger
15
16		_, _, active := sesh.Pty()
17		if !active {
18			logger.Info("no active terminal, skipping")
19			return nil, nil
20		}
21
22		dbpool := postgres.NewDB(cfg.DbURL, cfg.Logger)
23		renderer := bm.MakeRenderer(sesh)
24		styles := common.DefaultStyles(renderer)
25
26		shrd := common.SharedModel{
27			Session: sesh,
28			Cfg:     cfg,
29			Dbpool:  dbpool,
30			Styles:  styles,
31			Width:   80,
32			Height:  24,
33			Logger:  logger,
34		}
35
36		m := NewUI(shrd)
37
38		opts := bm.MakeOptions(sesh)
39		opts = append(opts, tea.WithAltScreen())
40		return m, opts
41	}
42}