repos / pico

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

pico / shared
Eric Bower · 07 May 24

senpai.go

 1package shared
 2
 3import (
 4	"git.sr.ht/~delthas/senpai"
 5	"github.com/charmbracelet/ssh"
 6)
 7
 8type Vtty struct {
 9	ssh.Session
10}
11
12func (v Vtty) Drain() error {
13	_, err := v.Write([]byte("\033[?25h\033[0 q\033[34h\033[?25h\033[39;49m\033[m^O\033[H\033[J\033[?1049l\033[?1l\033>\033[?1000l\033[?1002l\033[?1003l\033[?1006l\033[?2004l"))
14	if err != nil {
15		return err
16	}
17
18	err = v.Exit(0)
19	if err != nil {
20		return err
21	}
22
23	err = v.Close()
24	return err
25}
26
27func (v Vtty) Start() error {
28	return nil
29}
30
31func (v Vtty) Stop() error {
32	return nil
33}
34
35func (v Vtty) WindowSize() (width int, height int, err error) {
36	pty, _, _ := v.Pty()
37	return pty.Window.Width, pty.Window.Height, nil
38}
39
40func (v Vtty) NotifyResize(cb func()) {
41	_, notify, _ := v.Pty()
42	go func() {
43		for range notify {
44			cb()
45		}
46	}()
47}
48
49func NewSenpaiApp(sesh ssh.Session, username, pass string) (*senpai.App, error) {
50	vty := Vtty{
51		sesh,
52	}
53	senpaiCfg := senpai.Defaults()
54	senpaiCfg.TLS = true
55	senpaiCfg.Addr = "irc.pico.sh:6697"
56	senpaiCfg.Nick = username
57	senpaiCfg.Password = &pass
58	senpaiCfg.Tty = vty
59
60	app, err := senpai.NewApp(senpaiCfg)
61	return app, err
62}