Documentation
¶
Overview ¶
Package transcript is the chat log: rows appended in order, drawn on demand, and a reader position that survives every redraw.
The transcript owns its viewport (ADR 0007). A reveal, a timestamp toggle or a resize changes how many screen lines each row takes, so the reader's place is held as an anchor, a row rather than a line offset, read before any mutation and restored after. Keeping the viewport inside is what makes that ordering an invariant of this package instead of something every caller has to remember.
Rows arrive already classified and stamped: the transcript styles what it is told and never reads the clock or the network. Username and HTML are treated as hostile and sanitized on draw; Text is trusted as the caller rendered it.
Index ¶
- Constants
- type Kind
- type Options
- type Row
- type Transcript
- func (t *Transcript) Append(r Row)
- func (t *Transcript) Follow()
- func (t Transcript) Following() bool
- func (t Transcript) Height() int
- func (t Transcript) Options() Options
- func (t *Transcript) PageDown()
- func (t *Transcript) PageUp()
- func (t *Transcript) Resize(w, h int)
- func (t Transcript) Rows() []Row
- func (t *Transcript) SetOptions(o Options)
- func (t Transcript) View() string
Constants ¶
const MaxRows = 2000
MaxRows caps the transcript. An evening of chat must not grow without bound; the oldest rows are dropped first, the same loss a reconnect gap is.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Kind ¶
type Kind int
Kind says what a row is, which decides how it is drawn.
const ( // Chat is an ordinary line: a styled speaker, then the body. Chat Kind = iota // Me is a /me action. The server's HTML already leads with the // actor's name, as the web client relies on; only the "* " is ours. Me // Slap is drawn like Me. Slap // Server is a server-authored message: HTML drawn as an event. Server // DM is a direct message, marked "[DM]" before the speaker. DM // Event is something that happened (a join, a notice, the MOTD): // plain Text drawn faint. Event // Error is something that failed: plain Text in the error color. Error // Roster is the /who listing: plain Text drawn as given, since it // carries its own dimming for away users. Roster // Gap marks a reconnect whose backfill did not overlap what was // already shown; older messages are gone. Gap )
type Row ¶
type Row struct {
Kind Kind
Username string
Mod bool
Self bool
Mention bool
Spoiler bool
HTML string
Text string
At time.Time
}
Row is one entry in the transcript. HTML is for Chat, Me, Slap, Server and DM and is converted on every draw so a reveal can show what a hidden spoiler held; Text is for Event, Error and Roster and must already be rendered and sanitized. At is always the caller's: the transcript never substitutes the current time.
type Transcript ¶
type Transcript struct {
// contains filtered or unexported fields
}
Transcript is the chat log and the viewport it is read through. The zero value is not usable; call New. It is a value type like the viewport it holds, so a Bubble Tea model can carry it by value.
func New ¶
func New(t theme.Theme) Transcript
New builds an empty transcript drawing with the theme's roles.
func (*Transcript) Append ¶
func (t *Transcript) Append(r Row)
Append adds a row at the bottom. A reader following the newest row keeps following; one scrolled up stays on the row they were reading, even when the cap drops rows above it.
func (*Transcript) Follow ¶
func (t *Transcript) Follow()
Follow jumps to the newest row and keeps the reader there.
func (Transcript) Following ¶
func (t Transcript) Following() bool
Following reports whether the reader is at the bottom. Before the first Resize there is nothing to be scrolled up in, so it is true.
func (Transcript) Height ¶
func (t Transcript) Height() int
Height is the viewport's row count as of the last Resize.
func (Transcript) Options ¶
func (t Transcript) Options() Options
Options reports the current display toggles.
func (*Transcript) PageUp ¶
func (t *Transcript) PageUp()
PageUp scrolls back one screen; the reader stops following.
func (*Transcript) Resize ¶
func (t *Transcript) Resize(w, h int)
Resize fits the transcript to w columns and h rows. A new width re-wraps every row around the reader's anchor; a height-only change keeps the content and only reclamps, so a reader at the bottom stays there and one left past the bottom by a shrink snaps back.
func (Transcript) Rows ¶
func (t Transcript) Rows() []Row
Rows is what the transcript holds, oldest first. The slice is the transcript's own; callers read it and do not keep it.
func (*Transcript) SetOptions ¶
func (t *Transcript) SetOptions(o Options)
SetOptions changes the display toggles and redraws every row around the reader's anchor.
func (Transcript) View ¶
func (t Transcript) View() string
View draws the visible screen lines, or nothing before the first Resize.