File: activeterm.go

package info (click to toggle)
golang-github-charmbracelet-wish 0.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 164 kB
  • sloc: makefile: 3
file content (21 lines) | stat: -rw-r--r-- 434 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Package activeterm provides a middleware to block inactive PTYs.
package activeterm

import (
	"github.com/charmbracelet/wish"
	"github.com/gliderlabs/ssh"
)

// Middleware will exit 1 connections trying with no active terminals.
func Middleware() wish.Middleware {
	return func(sh ssh.Handler) ssh.Handler {
		return func(s ssh.Session) {
			_, _, active := s.Pty()
			if !active {
				s.Exit(1)
				return
			}
			sh(s)
		}
	}
}