winch

package
v0.9.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package winch distributes a session's window-size changes to every reader that wants them.

ssh.Session.Pty returns one channel per session, on SSH and telnet alike, so only one reader can take each change. The session loop that resizes the terminal ranged over it for the whole connection, and the full-screen editor, a door and a file transfer each took from the same channel while they ran, so whichever reader won the receive got the change and the others missed it. The session loop now owns the channel through a Hub and the others subscribe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Subscribe

func Subscribe(s ssh.Session) (<-chan ssh.Window, func())

Subscribe is Hub.Subscribe on the Hub that owns s's window changes. With no Hub, as in tests and tools that run a screen without the session loop, it returns the channel s.Pty gives, which only one reader may take from, and a stop that does nothing.

Types

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub takes a session's window changes from the one channel its transport provides and hands each to every subscriber.

func Own

func Own(s ssh.Session, src <-chan ssh.Window) (*Hub, <-chan ssh.Window)

Own gives s a Hub that takes src's changes from now on, and returns the owner's subscription, which sees every change src delivers, including one already waiting in it. Call Close when the session ends: a transport that never closes src would otherwise keep the Hub's goroutine.

func (*Hub) Close

func (h *Hub) Close()

Close ends every subscription by closing its channel, stops taking from the source and forgets the Hub, so Subscribe for the session falls back to Pty.

The Hub is forgotten before any subscriber's channel closes, and under the same lock that Subscribe takes, so a reader that sees its channel closed and then looks the session up, or subscribes again, finds the Hub gone. With the registry removed after the unlock, as before, a reader could run between the two and still find it (#906).

func (*Hub) Subscribe

func (h *Hub) Subscribe() (<-chan ssh.Window, func())

Subscribe returns a channel of the changes that arrive from now on, holding the latest while its reader is busy, and a func that ends the subscription. The channel is closed when the Hub closes; on a Hub already closed it comes back closed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址