repos / pico

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

pico / wish
Eric Bower · 16 May 24

mdw.go

 1package wish
 2
 3import (
 4	"fmt"
 5
 6	"github.com/charmbracelet/ssh"
 7	"github.com/charmbracelet/wish"
 8	bm "github.com/charmbracelet/wish/bubbletea"
 9	"github.com/picosh/pico/tui/common"
10)
11
12func SessionMessage(sesh ssh.Session, msg string) {
13	_, _ = sesh.Write([]byte(msg + "\r\n"))
14}
15
16func DeprecatedNotice() wish.Middleware {
17	return func(next ssh.Handler) ssh.Handler {
18		return func(sesh ssh.Session) {
19
20			renderer := bm.MakeRenderer(sesh)
21			styles := common.DefaultStyles(renderer)
22
23			msg := fmt.Sprintf(
24				"%s\n\nRun %s to access pico's TUI",
25				styles.Logo.Render("DEPRECATED"),
26				styles.Code.Render("ssh pico.sh"),
27			)
28			SessionMessage(sesh, styles.RoundedBorder.Render(msg))
29			next(sesh)
30		}
31	}
32}
33
34func PtyMdw(mdw wish.Middleware) wish.Middleware {
35	return func(next ssh.Handler) ssh.Handler {
36		return func(sesh ssh.Session) {
37			_, _, ok := sesh.Pty()
38			if !ok {
39				next(sesh)
40				return
41			}
42			mdw(next)(sesh)
43		}
44	}
45}