chat

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 22 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

Index

Constants

View Source
const DuplicateBypass = rune(917504)

DuplicateBypass is the invisible rune the tab inserts to keep Twitch from collapsing an intentionally repeated message. It must never be rendered.

Variables

This section is empty.

Functions

func FormatBadgeReplacement

func FormatBadgeReplacement(settings save.Settings, replacements map[string]string) string

FormatBadgeReplacement renders a badge set for text-mode output.

func GraphicRows

func GraphicRows(settings save.Settings) int

GraphicRows returns the number of terminal rows graphic emotes and badges occupy, or 1 when graphics are disabled.

func Snippet

func Snippet(message string) string

Snippet normalizes a message into one line for a reply indicator or quote.

func StripANSI

func StripANSI(s string) string

func TruncateToWidth

func TruncateToWidth(s string, width int) string

TruncateToWidth shortens s so it renders in at most width cells.

Types

type Buffer

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

Buffer is one chat transcript: entries, rendered rows, selection, viewport, search filter and new-message badge. It has no key handling, search widget or tab mode; the tab shell owns those and calls this module.

func New

func New(width, height int, settings save.Settings, theme save.Theme) *Buffer

New creates an empty transcript.

func (*Buffer) Append

func (b *Buffer) Append(msg ChatEventMessage) tea.Cmd

Append adds one event and returns a smooth-scroll command when the viewport follows the newest message.

func (*Buffer) Badge

func (b *Buffer) Badge() (string, int)

func (*Buffer) BadgeHit

func (b *Buffer) BadgeHit(row, col int) bool

func (*Buffer) BadgeSpan

func (b *Buffer) BadgeSpan(renderStart, height, width int) (row, col int, ok bool)

func (*Buffer) CaughtUp

func (b *Buffer) CaughtUp() bool

CaughtUp reports whether the newest line is visible or selected.

func (*Buffer) ClearFilter

func (b *Buffer) ClearFilter()

ClearFilter removes the search filter and shows the whole transcript again.

func (*Buffer) ClipboardText

func (b *Buffer) ClipboardText(id EntryID) string

ClipboardText returns the plain-text form of one entry.

func (*Buffer) Current

func (b *Buffer) Current() (int, *Entry)

Current returns the index and pointer of the entry under the cursor.

func (*Buffer) CursorLine

func (b *Buffer) CursorLine() int

func (*Buffer) DebugDump

func (b *Buffer) DebugDump()

func (*Buffer) EmoteNameAt

func (b *Buffer) EmoteNameAt(row, col int) (string, bool)

EmoteNameAt returns the graphic emote name at a viewport cell.

func (*Buffer) Entries

func (b *Buffer) Entries() []Entry

Entries returns a copy of the transcript entries in order.

func (*Buffer) Entry

func (b *Buffer) Entry(id EntryID) (Entry, bool)

Entry returns one entry by ID.

func (*Buffer) EntryAtLine

func (b *Buffer) EntryAtLine(line int) (int, *Entry)

EntryAtLine returns the index and pointer of the entry containing an absolute rendered line.

func (*Buffer) FilterStatus

func (b *Buffer) FilterStatus() FilterStatus

FilterStatus returns the last filter result.

func (*Buffer) HandleChatClick

func (b *Buffer) HandleChatClick(row, col int) bool

HandleChatClick consumes a click on the new-message badge or a reply reference.

func (*Buffer) Hit

func (b *Buffer) Hit(row int) (EntryID, bool)

func (*Buffer) IsFiltering

func (b *Buffer) IsFiltering() bool

IsFiltering reports whether a filter is currently applied.

func (*Buffer) LineRange

func (b *Buffer) LineRange(id EntryID) (int, int, bool)

LineRange returns the absolute rendered rows occupied by an entry.

func (*Buffer) MessageDown

func (b *Buffer) MessageDown(n int)

MessageDown moves the selection down n messages.

func (*Buffer) MessageUp

func (b *Buffer) MessageUp(n int)

MessageUp moves the selection up n messages.

func (*Buffer) Move

func (b *Buffer) Move(n int)

func (*Buffer) MoveToBottom

func (b *Buffer) MoveToBottom()

MoveToBottom selects the newest entry.

func (*Buffer) MoveToTop

func (b *Buffer) MoveToTop()

MoveToTop selects the first entry.

func (*Buffer) NewMessages

func (b *Buffer) NewMessages() int

NewMessages returns the number of messages that arrived while scrolled up.

func (*Buffer) Newest

func (b *Buffer) Newest() (Entry, bool)

Newest returns the newest entry.

func (*Buffer) NewestPtr

func (b *Buffer) NewestPtr() *Entry

func (*Buffer) PageDown

func (b *Buffer) PageDown()

PageDown moves the selection down one page.

func (*Buffer) PageUp

func (b *Buffer) PageUp()

PageUp moves the selection up one page.

func (*Buffer) Palette

func (b *Buffer) Palette() *Palette

Palette returns the shared user-color palette.

func (*Buffer) RawRows

func (b *Buffer) RawRows() []string

func (*Buffer) ReplaceNotice

func (b *Buffer) ReplaceNotice(id, message string) bool

ReplaceNotice rewrites an existing notice in place and reflows the rows after its text changed. It returns false when the notice left the buffer.

func (*Buffer) ResetFilter

func (b *Buffer) ResetFilter()

ResetFilter removes the filter without moving the selection. The search widget calls it when it opens, so entering search does not jump to the tail.

func (*Buffer) Resize

func (b *Buffer) Resize(width, height int)

Resize updates the transcript dimensions.

func (*Buffer) Rows

func (b *Buffer) Rows(height int) ([]string, int)

Rows returns the visible rows and the absolute line the first row represents. The selection indicator and the new-message badge are already applied.

func (*Buffer) ScrollByLines

func (b *Buffer) ScrollByLines(n int)

ScrollByLines moves the selection by n rendered lines.

func (*Buffer) Select

func (b *Buffer) Select(id EntryID) bool

Select selects an entry by ID.

func (*Buffer) SelectAtViewportRow

func (b *Buffer) SelectAtViewportRow(row int)

SelectAtViewportRow selects the entry at a viewport row.

func (*Buffer) SelectLine

func (b *Buffer) SelectLine(line int)

SelectLine selects the entry containing the absolute rendered line.

func (*Buffer) Selected

func (b *Buffer) Selected() (Entry, bool)

Selected returns the selected entry.

func (*Buffer) SetFilter

func (b *Buffer) SetFilter(query string) FilterStatus

SetFilter applies a search query. Queries shorter than three characters show the hint and leave the transcript unfiltered.

func (*Buffer) SetSearchActive

func (b *Buffer) SetSearchActive(active bool)

func (*Buffer) SetTheme

func (b *Buffer) SetTheme(theme save.Theme)

SetTheme repaints the transcript with a new theme.

Rendered rows carry their colors inline, so the whole transcript is re-rendered from its entries. Selection, scroll position, search filter and the new-message counter are carried over: a theme switch must not move the user's viewport.

func (*Buffer) SetTimeFormat

func (b *Buffer) SetTimeFormat(format string)

SetTimeFormat changes the timestamp format of rendered messages.

func (*Buffer) SnapScroll

func (b *Buffer) SnapScroll()

SnapScroll stops the smooth-scroll animation at the current viewport.

func (*Buffer) TimePaddingWidth

func (b *Buffer) TimePaddingWidth() int

func (*Buffer) Update

func (b *Buffer) Update(msg tea.Msg) (cmd tea.Cmd, handled bool)

Update handles the messages the transcript owns. handled is false for every other message, so the tab shell can route keys and the search widget.

func (*Buffer) UpdatePort

func (b *Buffer) UpdatePort()

func (*Buffer) UsePalette

func (b *Buffer) UsePalette(palette *Palette)

UsePalette shares another transcript's user colors.

func (*Buffer) ViewportRenderStart

func (b *Buffer) ViewportRenderStart() int

ViewportRenderStart returns the absolute line of the first visible row.

type ChatEventMessage

type ChatEventMessage struct {
	// IsFakeEvent marks an event created by local input or history load rather
	// than a live IRC connection.
	IsFakeEvent             bool
	AccountID               string
	Channel                 string
	ChannelID               string
	ChannelGuestID          string // source-room-id by twitch
	ChannelGuestDisplayName string // set later when the tab reads the message

	Message         twitchirc.IRCer
	DisplayModifier MessageContentModifier // modifier for the original irc message

	// TabID addresses the event to one tab. Empty means every tab.
	TabID string

	// PrepareCommand is a kitty graphics command the shell writes before the
	// event is rendered. The transcript itself never consumes it.
	PrepareCommand string
}

ChatEventMessage is one event shown in a chat transcript. The fields are exported because the shell assembles the message: it owns the emote/badge replacers and the link checker, and it builds the event before it knows which transcript will receive it.

type Entry

type Entry struct {
	ID      EntryID
	Event   ChatEventMessage
	Deleted bool
	// contains filtered or unexported fields
}

Entry is one chat event in the transcript. Position, selection and filter state stay private: callers identify an entry by EntryID and read its Event.

func (Entry) Selected

func (e Entry) Selected() bool

Selected reports whether this entry currently carries the selection.

type EntryID

type EntryID int

EntryID identifies one transcript entry. It stays valid for the lifetime of the buffer; positions and line numbers are deliberately not part of the interface because they change on every reflow.

type FilterStatus

type FilterStatus struct {
	Applied bool
	Matches int
	Err     string
	Hint    string
}

FilterStatus reports what happened to the search filter.

type MessageContentModifier

type MessageContentModifier struct {
	WordReplacements WordReplacement
	BadgeReplacement WordReplacement
	MessageSuffix    string
	Strikethrough    bool
	Italic           bool
}

type Palette

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

Palette owns the per-user color render functions. Rendered chat messages, the user inspect window and the composer suggestions all read from the same palette, so a user keeps the same color everywhere.

The zero value is not usable; construct one with NewPalette.

func NewPalette

func NewPalette() *Palette

func (*Palette) Lookup

func (p *Palette) Lookup(name string) (func(...string) string, bool)

Lookup returns the cached render function for name.

func (*Palette) Names

func (p *Palette) Names() []string

Names returns the cached user names in sorted order, for diagnostics.

func (*Palette) Prune

func (p *Palette) Prune(keep map[string]struct{})

Prune drops every user not in keep. Logins are compared case-insensitively because Twitch logins are.

func (*Palette) Renderer

func (p *Palette) Renderer(name, colorHex string) func(...string) string

Renderer returns the render function for name, creating and caching one from colorHex when the user is seen for the first time. An empty colorHex falls back to a random color.

type WordReplacement

type WordReplacement map[string]string // og:replacement

Jump to

Keyboard shortcuts

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