File: main.go

package info (click to toggle)
golang-github-aymanbagabas-go-osc52 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, forky, sid, trixie
  • size: 88 kB
  • sloc: makefile: 2
file content (40 lines) | stat: -rw-r--r-- 807 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main

import (
	"fmt"
	"log"

	"github.com/aymanbagabas/go-osc52"
	"github.com/charmbracelet/wish"
	"github.com/gliderlabs/ssh"
)

func main() {
	s, err := wish.NewServer(
		wish.WithAddress(":2222"),
		wish.WithHostKeyPath("ssh_host_key"),
		wish.WithMiddleware(
			middleware(),
		),
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("SSH into %s\n", s.Addr)
	s.ListenAndServe()
}

func middleware() wish.Middleware {
	return func(h ssh.Handler) ssh.Handler {
		return func(s ssh.Session) {
			environ := s.Environ()
			pty, _, _ := s.Pty()
			// Put TERM environment variable into environ.
			environ = append(environ, fmt.Sprintf("TERM=%s", pty.Term))
			out := osc52.NewOutput(s, environ)
			str := "hello world"
			out.Copy(str)
			s.Write([]byte(fmt.Sprintf("Copied %q!\n", str)))
		}
	}
}