Eric Bower
·
30 Nov 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/muesli/termenv"
8 "github.com/picosh/pico/db/postgres"
9 "github.com/picosh/pico/shared"
10 "github.com/picosh/pico/tui/common"
11)
12
13func CmsMiddleware(cfg *shared.ConfigSite) bm.Handler {
14 return func(sesh ssh.Session) (tea.Model, []tea.ProgramOption) {
15 logger := cfg.Logger
16
17 _, _, active := sesh.Pty()
18 if !active {
19 logger.Info("no active terminal, skipping")
20 return nil, nil
21 }
22
23 dbpool := postgres.NewDB(cfg.DbURL, cfg.Logger)
24 renderer := bm.MakeRenderer(sesh)
25 renderer.SetColorProfile(termenv.TrueColor)
26 styles := common.DefaultStyles(renderer)
27
28 shrd := &common.SharedModel{
29 Session: sesh,
30 Cfg: cfg,
31 Dbpool: dbpool,
32 Styles: styles,
33 Width: 80,
34 Height: 24,
35 Logger: logger,
36 }
37
38 m := NewUI(shrd)
39 err := m.setupUser()
40 if err != nil {
41 return nil, nil
42 }
43
44 opts := bm.MakeOptions(sesh)
45 opts = append(opts, tea.WithAltScreen())
46 return m, opts
47 }
48}