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 ¶
- type Envelope
- type Environment
- type Host
- func (h *Host) AnswerPrompt(answer talk.Value) []string
- func (h *Host) Close()
- func (h *Host) FinishObjectReplay()
- func (h *Host) Input(source string) []string
- func (h *Host) Inspect() talk.Inspection
- func (h *Host) NeedsMore(source string) bool
- func (h *Host) NextDeadline() time.Time
- func (h *Host) Read(line string) []string
- func (h *Host) ReplayAnswer(item Item) (bool, []string)
- func (h *Host) ReplayObjectItem(index int)
- func (h *Host) Started() bool
- func (h *Host) Tick() []string
- func (h *Host) VirtualClock() bool
- func (h *Host) Waiting() Waiting
- type Item
- type Objects
- func (o *Objects) Action(request Envelope) Envelope
- func (o *Objects) DefineKind(def talk.ObjectKindDef) (*talk.ObjectKind, error)
- func (o *Objects) Encode(x talk.Value) json.RawMessage
- func (o *Objects) Object(kind *talk.ObjectKind, id string, native any) (*talk.Object, error)
- func (o *Objects) Request(fields map[string]any) Envelope
- type Prompt
- type Waiting
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 ¶
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 ¶
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) 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 ¶
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 ¶
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 (*Host) ReplayAnswer ¶
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 ¶
ReplayObjectItem gives the session a recorded envelope between Host calls: an object declaration, or a Host action, which the session performs again.
func (*Host) VirtualClock ¶
type Item ¶
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 ¶
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.