Skip to content

Commit

Permalink
chore: add ssh example
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Apr 15, 2022
1 parent 7565cd5 commit 730b6c3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
File renamed without changes.
40 changes: 40 additions & 0 deletions _examples/ssh/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)))
}
}
}

0 comments on commit 730b6c3

Please sign in to comment.