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) LineDown(n int)
- func (t *Transcript) LineUp(n int)
- func (t *Transcript) Oldest()
- 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) SetTheme(th theme.Theme)
- func (t *Transcript) SetToday(now time.Time)
- func (t Transcript) View() string
- func (t Transcript) YOffset() int
Constants ¶
const ChurnWindow = 10 * time.Second
ChurnWindow is how close a Left must follow its user's Joined for the two to collapse into one JoinedLeft row. A tab opened by mistake or a client that fails right after joining comes and goes inside a few seconds; a real visit lasts longer.
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): plain Text // drawn faint. Event // MOTD is the server's message of the day: HTML drawn at full // strength in a titled box with a blank line either side, so the // first thing read on join does not sink into the history above it. MOTD // 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. Drawn as a divider. Gap // Reconnected marks a reconnect that lost nothing, so a reader can // still tell a blip happened. Drawn as a faint divider with the // time, from At. Reconnected // Joined is Username arriving in the channel, drawn as an event. Joined // Left is Username leaving. Appended within ChurnWindow of a Joined // from the same user, it is not added: the Joined row becomes // JoinedLeft instead. Left // JoinedLeft is a join and a leave from one user close together, // collapsed into one faint centered row so a flaky connection does // not fill the screen with pairs. Callers never append it. JoinedLeft // Unread marks where the reader stopped reading: drawn as a divider // naming At, the time they looked away. The transcript holds at most // one; appending another removes the old one, so the mark moves // rather than piling up. Unread // Card is a local reference card, such as the key list: plain Text, // one "term\tdefinition" entry per line, drawn in the MOTD's box // under Title so it reads as something to look up rather than // something said. The transcript aligns the definitions itself, so // one that wraps hangs under its own column, never under the terms. Card )
type Row ¶
type Row struct {
Kind Kind
Username string
Mod bool
Self bool
Mention bool
Spoiler bool
HTML string
Text string
Title string
At time.Time
}
Row is one entry in the transcript. HTML is for Chat, Me, Slap, Server, DM and MOTD and is converted on every draw so a reveal can show what a hidden spoiler held; Text is for Event, Error, Roster and Card and must already be rendered and sanitized. Title is Card's box title. Username is the speaker, or for Joined and Left who came or went. 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. Appending an Unread row removes the one already held, if any.
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) LineDown ¶
func (t *Transcript) LineDown(n int)
LineDown scrolls forward n lines, clamped at the bottom.
func (*Transcript) LineUp ¶
func (t *Transcript) LineUp(n int)
LineUp scrolls back n lines; the reader stops following.
func (*Transcript) Oldest ¶
func (t *Transcript) Oldest()
Oldest jumps to the oldest row held, the top of the backfill buffer. It loads nothing older: the transcript only has what arrived.
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) SetTheme ¶
func (t *Transcript) SetTheme(th theme.Theme)
SetTheme redraws every row in t's roles around the reader's anchor. It exists for the one swap a run makes: the UI starts in the dark theme and learns the terminal is light only once the terminal answers its background query, by which time rows may already be held. Rows drawn from HTML take the new colors; Text the caller already rendered (Event, Error, Roster) keeps the colors it was rendered with.
func (*Transcript) SetToday ¶
func (t *Transcript) SetToday(now time.Time)
SetToday gives the transcript the date the reader is on, which the first held row is compared with: one from an earlier day is led by its day divider, so a backfill that is all yesterday's says so. The transcript never reads the clock itself. The UI sets it once at launch; a session that runs past midnight is still marked by the divider above the first row of the new day.
func (Transcript) View ¶
func (t Transcript) View() string
View draws the visible screen lines, or nothing before the first Resize.
func (Transcript) YOffset ¶
func (t Transcript) YOffset() int
YOffset is the index of the top visible screen line. The UI tests read it to check line scrolling.