session

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

internal/session/session.go Session wires a PTY process to the emulator, the event log, and viewer fan-out. The session never depends on any viewer connection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	ID   int
	Msgs <-chan terminal.ServerMessage
}

type Config

type Config struct {
	Argv       []string
	Cols, Rows int
	LogPath    string
}

type Proc

type Proc interface {
	Write(p []byte) (int, error)
	Resize(cols, rows int) error
	Wait() int
	Stop()
}

func StartProc

func StartProc(argv []string, cols, rows int, onOutput func([]byte)) (Proc, error)

StartProc spawns argv on a new PTY. onOutput is called from a single goroutine with each chunk read from the PTY until child exit. The byte slice passed to onOutput is only valid for the duration of the call; consumers that retain the bytes must copy them.

type Session

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

func New

func New(cfg Config, start func(argv []string, cols, rows int, onOutput func([]byte)) (Proc, error)) (*Session, error)

func (*Session) Attach

func (s *Session) Attach(since uint64, size Size) (*Attachment, error)

Attach adds a viewer and decides what it opens with, from its cursor:

  • 0 — "I hold no cursor": a snapshot of the current screen, then live output. Every plain attach, and the only shape a fresh viewer should ever cost the log (spec §5: never repaint a screen by replaying raw bytes).
  • terminal.SinceAll — "the whole log": every entry from the first, then live. What `rainier attach --since 0` asks for, and the only way to read output that has already scrolled off the screen — a failed setup's full log, an overnight session's history.
  • anything else — a resume cursor: the entries after it, then live.

The last two both fall back to the snapshot when the log cannot answer them (an empty log, or a cursor already past its end): a viewer must never open on silence with no screen and no size.

func (*Session) Detach

func (s *Session) Detach(id int)

func (*Session) ExitCode

func (s *Session) ExitCode() int

func (*Session) Exited

func (s *Session) Exited() <-chan struct{}

func (*Session) SetSize

func (s *Session) SetSize(id int, size Size)

func (*Session) Stdin

func (s *Session) Stdin(p []byte)

func (*Session) Stop

func (s *Session) Stop()

Stop signals the agent process to terminate (SIGTERM). The normal exit path (close viewers, close exited) then runs. Safe to call more than once.

type Size

type Size struct{ Cols, Rows int }

func EffectiveSize

func EffectiveSize(viewers []Size) (Size, bool)

Jump to

Keyboard shortcuts

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