render

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 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 render turns session events into readable terminal lines: one event becomes one or a few lines, streamed agent text is joined, and charts and tables in answers are drawn.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisplayToolName added in v0.1.1

func DisplayToolName(name string) string

DisplayToolName shows the sandbox's own browser tools by the product's name (DEC-141): `rafiiq-browser_http_request` reads `waniis-browser_http_request`.

func FormatElapsed added in v0.1.1

func FormatElapsed(d time.Duration) string

FormatElapsed writes a duration the way the chat shows it: "6s", "1m 05s".

func FormatMarkdown

func FormatMarkdown(text string, o MDOptions) string

FormatMarkdown renders a whole answer at once.

func FromPerson added in v0.1.1

func FromPerson(name, login string) string

FromPerson is the name to show for one entry of the people route: the display name, else the GitHub login, never an id.

func LooksLikeID added in v0.1.1

func LooksLikeID(s string) bool

LooksLikeID reports whether s is one of the API's ids. The people route answers with the id as the name when it knows nothing better, and that must never be shown.

Types

type MD

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

MD turns streamed Markdown into terminal text: charts become a plot and a table, Markdown tables become aligned tables. With colors on, the rest is styled too: headings, **bold**, *italic*, `code`, links, lists, quotes and rules, and code blocks are syntax highlighted; without colors it passes through as written. Text can arrive in any chunking; ordinary lines are written as soon as their first word is known, so a streamed answer reads live.

func NewMD

func NewMD(w io.Writer, o MDOptions) *MD

NewMD writes to w.

func (*MD) Flush

func (m *MD) Flush()

Flush finishes the text: an unfinished block is printed as written, and an open line ends.

func (*MD) Open

func (m *MD) Open() bool

Open reports whether a line is half written.

func (*MD) Write

func (m *MD) Write(s string)

Write adds a chunk of text.

type MDOptions

type MDOptions struct {
	Style style.Style
	Width int  // terminal columns, for plots
	Draw  bool // draw charts above their tables
}

MDOptions say how an answer's Markdown is shown in a terminal.

type Options

type Options struct {
	Style      style.Style
	Width      int  // terminal columns (0: 80)
	Charts     bool // draw plots above chart tables
	Live       bool // stream agent text as it arrives and show tool calls when they start
	Timestamps bool
	// People names the people in the session: the signed-in person reads "you", others by their
	// name, anyone unknown "someone"; "rafiiq" and agents read "Waniis". Ids are never shown.
	People *People
	// Names is a plain id-to-name map, used when People is nil.
	Names map[string]string
	// Chat is the interactive chat's transcript: a run's end is one quiet line ("✓ done · 6s")
	// and the start of a run is not announced (the live status line shows it).
	Chat bool
	// Own recognizes the echoes of messages this chat sent, which are not shown again.
	Own *Own
}

Options say how events are shown.

type Own added in v0.1.1

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

Own recognizes the events that echo what this chat just sent, so a message you typed is shown once, as you typed it, and not again when the server repeats it. A prompt is matched by its id (from the command's reply) or by its text, its author and how recently it was sent.

func NewOwn added in v0.1.1

func NewOwn(now func() time.Time) *Own

NewOwn returns an empty tracker; now is the injected clock (nil: nothing expires).

func (*Own) Expect added in v0.1.1

func (o *Own) Expect(text string)

Expect records that text is about to be sent.

func (*Own) Match added in v0.1.1

func (o *Own) Match(typ, author, self, promptID, text string) bool

Match reports whether the event (its type, author, prompt id and text) echoes something this chat sent. self is the signed-in person's id, "" when unknown (then any author matches).

func (*Own) Sent added in v0.1.1

func (o *Own) Sent(promptID string)

Sent records the prompt id the server answered with.

type People added in v0.1.1

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

People says who is who in a session, so events read "Sara" and never "usr_01…". The signed-in person reads "you". Someone it doesn't know reads "someone". It is safe for concurrent use.

func NewPeople added in v0.1.1

func NewPeople(self string, names map[string]string) *People

NewPeople returns a resolver for the signed-in person's id (may be empty) and known names.

func (*People) Known added in v0.1.1

func (p *People) Known(id string) bool

Known reports whether id can be named: "you", Waniis or someone with a name.

func (*People) Merge added in v0.1.1

func (p *People) Merge(names map[string]string)

Merge adds names; an empty or id-like name is ignored.

func (*People) Name added in v0.1.1

func (p *People) Name(id string) string

Name is what to call id.

func (*People) Self added in v0.1.1

func (p *People) Self() string

Self is the signed-in person's id, "" when unknown.

func (*People) SetSelf added in v0.1.1

func (p *People) SetSelf(id string)

SetSelf records who the signed-in person is.

func (*People) Unknown added in v0.1.1

func (p *People) Unknown(ev api.Event) []string

Unknown lists the user ids an event mentions that People can't name yet, so a caller can refresh the session's people before showing the event.

type Renderer

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

Renderer writes events to w. It is stateful (it pairs tool calls with results and joins streamed deltas), so use one per stream and call Flush at the end.

func New

func New(w io.Writer, o Options) *Renderer

New builds a renderer.

func (*Renderer) Event

func (r *Renderer) Event(ev api.Event)

Event renders one event.

func (*Renderer) Flush

func (r *Renderer) Flush()

Flush finishes the output: an open agent line ends, buffered text and unfinished tool calls are written.

func (*Renderer) Prime added in v0.1.1

func (r *Renderer) Prime(events []api.Event)

Prime tells the renderer about events that were shown earlier (or not at all), so that what follows is understood: a run that began before the stream was joined still gets its duration.

Jump to

Keyboard shortcuts

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