session

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package session is chapter 12's Session Host for Go. Its Session Commands, observation, `:describe`, inspection and Transcript replay are the Zig Session Host's, which the embedded reactor serves as `session-v1` (ADR 0180): each Host runs one guest, which owns the session's Group. Go keeps the Session Driver's side: its Environment supplies the Clock, files and live Host Objects, and receives the Transcript and the Trace.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Envelope

type Envelope map[string]json.RawMessage

Envelope is raw ordered Value Encoding inside a strict JSON framing object.

func ParseEnvelope

func ParseEnvelope(source string) (e Envelope, err error)

type Environment

type Environment struct {
	Objects          func(*Objects) map[string]*talk.Object
	ResolveObject    func(kind, id string) (any, bool)
	ObjectTranscript []Item
	Now              func() time.Time
	Record           func(Item)
	Trace            func(string)
	ReadFile         func(string) (string, error)
	WriteFile        func(directory, file, source string) error
	ReadStoreFile    func(path string) (string, error)
	WriteStoreFile   func(path, source string) error
}

Environment supplies host effects. Callbacks run synchronously; callers serialize the Host's calls. Record receives every Transcript Item the session makes, printed lines included, and Trace its Group's Trace lines.

Objects declares live Host Objects, whose property and collection callbacks the session calls through Go; ResolveObject answers a live Restore. ObjectTranscript is a recorded Transcript whose crossings and Restores answer the session's instead, as a replay does. Now reads the real Clock for each Host call. ReadFile and ReadStoreFile read the file `:library`, `:script`, `:fix` or `:store load` names, before the command goes to the session with the file's lines; WriteFile and WriteStoreFile write what `:export` and `:store save` make.

type Host

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

Host is one session, served by its own guest.

func New

func New(env Environment) *Host

New opens a session on a new guest. It panics if the embedded reactor can't serve one.

func (*Host) AnswerPrompt

func (h *Host) AnswerPrompt(answer talk.Value) []string

AnswerPrompt answers the user prompt the session waits for with what the person gave: a boolean, the chosen item or items, the entered text, or Nothing.

func (*Host) Close added in v0.4.0

func (h *Host) Close()

Close ends the session and its guest.

func (*Host) FinishObjectReplay

func (h *Host) FinishObjectReplay()

FinishObjectReplay ends a replay. The session checks each envelope as it comes, so there is nothing left to check.

func (*Host) Input

func (h *Host) Input(source string) []string

Input is one Entry or Session Command, with any further lines after LF. A command that names a file is sent with the file's lines in its place.

func (*Host) Inspect

func (h *Host) Inspect() talk.Inspection

Inspect is the session Group's Inspection, as a Trace Case ends: its snapshot goes to the Trace, and nothing is recorded.

func (*Host) NeedsMore

func (h *Host) NeedsMore(source string) bool

NeedsMore reports whether source, the lines a Driver has collected, waits for more before it is a whole Entry or Session Command, as the session's own names read it.

func (*Host) NextDeadline

func (h *Host) NextDeadline() time.Time

func (*Host) Read

func (h *Host) Read(line string) []string

Read gives a `read` the session waits for its line.

func (*Host) ReplayAnswer

func (h *Host) ReplayAnswer(item Item) (bool, []string)

ReplayAnswer gives a Transcript's `~` line to the session: a prompt's answer answers it, and a `user busy` the session recorded itself is skipped.

func (*Host) ReplayObjectItem

func (h *Host) ReplayObjectItem(index int)

ReplayObjectItem gives the session a recorded envelope between Host calls: an object declaration, or a Host action, which the session performs again.

func (*Host) Started

func (h *Host) Started() bool

func (*Host) Tick

func (h *Host) Tick() []string

Tick is a Pump at a deadline.

func (*Host) VirtualClock

func (h *Host) VirtualClock() bool

func (*Host) Waiting

func (h *Host) Waiting() Waiting

type Item

type Item struct {
	Kind, Text, Call string
	At               time.Time
}

Item is one Transcript record. Kind is input, read, clock, answer, envelope, comment or output; an input's continuation lines are folded into Text with LF.

type Objects

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

Objects is the context Environment.Objects declares live Host Objects in. The session's guest holds them; each property get or set, and each Object Collection count, at or find, is a `prop` need Go answers by calling the kind's callbacks. Request and Action hand the session Host actions.

func (*Objects) Action

func (o *Objects) Action(request Envelope) Envelope

Action hands the session a Host action whose Values are already encoded, as Encode writes them.

func (*Objects) DefineKind

func (o *Objects) DefineKind(def talk.ObjectKindDef) (*talk.ObjectKind, error)

DefineKind declares an Object Kind, whose callbacks answer the session's crossings.

func (*Objects) Encode

func (o *Objects) Encode(x talk.Value) json.RawMessage

Encode is x as a session envelope holds it: a Host Object by its identity, and a Function Value the session exposed by its handle.

func (*Objects) Object

func (o *Objects) Object(kind *talk.ObjectKind, id string, native any) (*talk.Object, error)

Object declares a Host Object of a kind DefineKind declared.

func (*Objects) Request

func (o *Objects) Request(fields map[string]any) Envelope

Request hands the session a Host action, encoding each Value as a session envelope holds it, and returns its reply. During a crossing, the action goes with the crossing's answer, and its reply is nil: the session records it.

type Prompt

type Prompt struct {
	Kind, Message, Prompt, Fallback string
	Items                           []string
	Multiple                        bool
}

Prompt is a user prompt as the person sees it (chapter 12, Prompts). Kind is confirm, choose or enter; an omitted prompt, default or title is "".

type Waiting

type Waiting struct {
	Kind   string
	At     time.Time
	Call   string
	Prompt *Prompt
}

Waiting is what the Session Host waits for: prompt, read, user (with the prompt's Call and Prompt) or deadline (with At).

Jump to

Keyboard shortcuts

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