tab

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: 50 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

Overview

Package tab implements the tabs a chatuino session is made of.

A tab owns everything behind one header entry: its own model, its own children (chat window, composer, modals), its own state machine and the messages it exchanges with the shell. The shell only knows this interface plus the concrete constructors (NewBroadcast, NewMention, NewLiveNotification) it calls when a tab is opened.

Index

Constants

This section is empty.

Variables

View Source
var LoadingSpinner = spinner.Points

LoadingSpinner is the unified spinner used across all loading states.

Functions

func Caption

func Caption(kind TabKind, account save.Account, channel string) (title, identity string)

Caption is the common source of tab/header labels. The shell can measure a prospective tab before constructing it and starting any owned resources.

func ExtractValidURLs

func ExtractValidURLs(text string) []string

func NewEmoteOverview

func NewEmoteOverview(channelID string, cache EmoteCache, replacer EmoteReplacer, graphicRows, width, height int) *emoteOverview

func NewLiveNotification

func NewLiveNotification(
	id string,
	width, height int,
	settings save.Settings,
	theme save.Theme,
	keymap save.KeyMap,
) *liveNotificationTab

func NewMention

func NewMention(
	id string,
	width, height int,
	settings save.Settings,
	theme save.Theme,
	keymap save.KeyMap,
	accountProvider AccountProvider,
) *mentionTab

func WheelDelta

func WheelDelta(msg tea.MouseWheelMsg) int

WheelDelta converts a wheel event into a line delta. Positive values scroll towards newer content. Tabs and the shell both scroll, so the conversion lives next to the interface both of them use.

Types

type APIClient

type APIClient interface {
	GetUsers(ctx context.Context, logins []string, ids []string) (twitchapi.UserResponse, error)
	GetStreamInfo(ctx context.Context, broadcastID []string) (twitchapi.GetStreamsResponse, error)
	GetChatSettings(ctx context.Context, broadcasterID string, moderatorID string) (twitchapi.GetChatSettingsResponse, error)
}

type AccountProvider

type AccountProvider interface {
	GetAllAccounts() ([]save.Account, error)
	UpdateTokensFor(id, accessToken, refreshToken string) error
	GetAccountBy(id string) (save.Account, error)
}

type BadgeReplacer

type BadgeReplacer interface {
	Replace(ctx context.Context, broadcasterID string, badgeList []twitchirc.Badge) (string, map[string]string, error)
	InjectContributorBadge(ctx context.Context, loginName string, badges map[string]string) (string, error)
}

type Broadcast

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

func NewBroadcast

func NewBroadcast(
	tabID string,
	width, height int,
	account save.Account,
	channel string,
	settings save.Settings,
	theme save.Theme,
	keymap save.KeyMap,
	client ClientCapabilities,
	pool ConnectionPool,
	recentMessages RecentMessageService,
	messageLogger MessageLogger,
	emoteCache EmoteCache,
	emoteReplacer EmoteReplacer,
	badgeCache *badge.Cache,
	badgeReplacer BadgeReplacer,
	chatSettings *chatstate.Cache,
) *Broadcast

func (*Broadcast) AccountID

func (t *Broadcast) AccountID() string

func (*Broadcast) Blur

func (t *Broadcast) Blur()

func (*Broadcast) Channel

func (t *Broadcast) Channel() string

func (*Broadcast) ChannelID

func (t *Broadcast) ChannelID() string

func (*Broadcast) Close

func (t *Broadcast) Close()

func (*Broadcast) Focus

func (t *Broadcast) Focus()

func (*Broadcast) Focused

func (t *Broadcast) Focused() bool

func (*Broadcast) HandleMouseClick

func (t *Broadcast) HandleMouseClick(msg tea.MouseClickMsg, x, y int) tea.Cmd

func (*Broadcast) HandleMouseLeave

func (t *Broadcast) HandleMouseLeave()

HandleMouseLeave clears the emote tooltip.

func (*Broadcast) HandleMouseMotion

func (t *Broadcast) HandleMouseMotion(x, y int)

HandleMouseMotion records the pointer position (tab-local) for the emote tooltip.

func (*Broadcast) HandleMouseWheel

func (t *Broadcast) HandleMouseWheel(msg tea.MouseWheelMsg, x, y int) tea.Cmd

func (*Broadcast) HandleResize

func (t *Broadcast) HandleResize()

HandleResize sizes the children and records the layout the view and the mouse handlers use. Widths are applied first because the composer and the stream info wrap, and their height depends on the width they are rendered at.

func (*Broadcast) ID

func (t *Broadcast) ID() string

func (*Broadcast) Identity

func (t *Broadcast) Identity() string

Identity is the account label shown next to the title.

func (*Broadcast) Init

func (t *Broadcast) Init() tea.Cmd

func (*Broadcast) InitWithUserData

func (t *Broadcast) InitWithUserData(userData twitchapi.UserData) tea.Cmd

func (*Broadcast) IsComposing

func (t *Broadcast) IsComposing() bool

IsComposing reports whether a text input inside the tab is capturing printable keys. The shell asks this to decide whether a key press is text or a command.

func (*Broadcast) IsDataLoaded

func (t *Broadcast) IsDataLoaded() bool

func (*Broadcast) IsSearching

func (t *Broadcast) IsSearching() bool

func (*Broadcast) Kind

func (t *Broadcast) Kind() TabKind

func (*Broadcast) LocalSubOnly

func (t *Broadcast) LocalSubOnly() bool

LocalSubOnly reports whether the tab drops non-subscriber messages locally.

func (*Broadcast) LocalUniqueOnly

func (t *Broadcast) LocalUniqueOnly() bool

LocalUniqueOnly reports whether the tab drops repeated messages locally.

func (*Broadcast) SetFullWidth

func (t *Broadcast) SetFullWidth(width int)

func (*Broadcast) SetLocalSubOnly

func (t *Broadcast) SetLocalSubOnly(v bool)

SetLocalSubOnly restores that filter when a session is reloaded.

func (*Broadcast) SetLocalUniqueOnly

func (t *Broadcast) SetLocalUniqueOnly(v bool)

SetLocalUniqueOnly restores that filter when a session is reloaded.

func (*Broadcast) SetSize

func (t *Broadcast) SetSize(width, height int)

func (*Broadcast) SetTheme

func (t *Broadcast) SetTheme(theme save.Theme)

SetTheme applies a new theme to the tab and everything below it.

func (*Broadcast) SetUpdateAvailable

func (t *Broadcast) SetUpdateAvailable(latest string)

SetUpdateAvailable makes the status bar advertise a newer version. An empty version clears the notice.

func (*Broadcast) StatusBarView

func (t *Broadcast) StatusBarView() string

StatusBarView returns the status bar for Root's shared status line.

func (*Broadcast) Title

func (t *Broadcast) Title() string

Title is the header label: the channel as the user entered it.

func (*Broadcast) Update

func (t *Broadcast) Update(msg tea.Msg) (Tab, tea.Cmd)

func (*Broadcast) View

func (t *Broadcast) View() string

View renders the tab including the status bar.

func (*Broadcast) ViewWithoutStatusBar

func (t *Broadcast) ViewWithoutStatusBar() string

ViewWithoutStatusBar returns the body for a pane or vertical tab-list view; Root renders the focused tab's status bar at full terminal width.

type ChannelSuggestionsLoadedMessage

type ChannelSuggestionsLoadedMessage struct {
	Channels []string
}

ChannelSuggestionsLoadedMessage delivers channel names for /join autocomplete.

type ClientCapabilities

type ClientCapabilities struct {
	API        APIClient
	Chat       UserAuthenticatedAPI
	Moderation ModerationAPI
	Emotes     UserEmoteClient
	EventSub   wspool.EventSubService
	Follows    FollowedChannelsAPI
}

ClientCapabilities is what one account's API client can actually do.

The shell fills in only the capabilities the account has: an account signed in with its own token gets all of them, an anonymous account gets the server proxy and nothing else. A nil field means "not available for this account", so callers test the field instead of asserting an interface at every call site. Because each capability is a separate field, wiring a client into them also makes the compiler check it: assigning a client that lacks a method does not compile, where a type assertion would only fail once that path was reached.

type ConnectionPool

type ConnectionPool interface {
	ConnectIRC(accountID string) error
	DisconnectIRC(accountID string)
	SendIRC(accountID string, msg twitchirc.IRCer) error
	JoinChannel(accountID, channel string) error
	SubscribeEventSub(accountID string, req twitchapi.CreateEventSubSubscriptionRequest, service wspool.EventSubService) error
	Close() error
}

ConnectionPool manages WebSocket connections for IRC and EventSub.

type EmoteCache

type EmoteCache interface {
	GetByText(channelID, text string) (emote.Emote, bool)
	RefreshLocal(ctx context.Context, channelID string) error
	RefreshGlobal(ctx context.Context) error
	GetAllForChannel(id string) emote.EmoteSet
	AddUserEmotes(userID string, emotes []emote.Emote)
	AllEmotesUsableByUser(userID string) []emote.Emote
	RemoveEmoteSetForChannel(channelID string)
	LoadSetForeignEmote(emoteID, emoteText string) emote.Emote
}

type EmoteReplacer

type EmoteReplacer interface {
	Replace(ctx context.Context, channelID, content string, emoteList []twitchirc.Emote) (string, map[string]string, error)
}

type FollowedChannelsAPI

type FollowedChannelsAPI interface {
	FetchUserFollowedChannels(ctx context.Context, userID string, broadcasterID string) ([]twitchapi.FollowedChannel, error)
}

FollowedChannelsAPI lists the channels an account follows.

type JoinChannelMessage

type JoinChannelMessage struct {
	TabKind TabKind
	Channel string
	Account save.Account
}

JoinChannelMessage comes when user confirms channel which should be joined.

type MessageLogger

type MessageLogger interface {
	MessagesFromUserInChannel(username string, broadcasterChannel string) ([]messagelog.LogEntry, error)
}

type ModStatusFetcher

type ModStatusFetcher interface {
	GetModVIPList(ctx context.Context, channel string) (ivr.ModVIPResponse, error)
}

type ModerationAPI

type ModerationAPI interface {
	APIClient
	BanUser(ctx context.Context, broadcasterID string, moderatorID string, data twitchapi.BanUserData) error
	UnbanUser(ctx context.Context, broadcasterID string, moderatorID string, userID string) error
	DeleteMessage(ctx context.Context, broadcasterID string, moderatorID string, messageID string) error
	SendChatAnnouncement(ctx context.Context, broadcasterID string, moderatorID string, req twitchapi.CreateChatAnnouncementRequest) error
	CreateStreamMarker(ctx context.Context, req twitchapi.CreateStreamMarkerRequest) (twitchapi.StreamMarker, error)
	UpdateChatSettings(ctx context.Context, broadcasterID string, moderatorID string, data twitchapi.ChatSettingsUpdateData) (twitchapi.GetChatSettingsResponse, error)
	GetModerators(ctx context.Context, broadcasterID string, userIDs []string) ([]twitchapi.ChatRoleUser, error)
	AddChannelModerator(ctx context.Context, broadcasterID string, userID string) error
	RemoveChannelModerator(ctx context.Context, broadcasterID string, userID string) error
	GetVIPs(ctx context.Context, broadcasterID string, userIDs []string) ([]twitchapi.ChatRoleUser, error)
	AddChannelVIP(ctx context.Context, broadcasterID string, userID string) error
	RemoveChannelVIP(ctx context.Context, broadcasterID string, userID string) error
	WarnChatUser(ctx context.Context, broadcasterID string, moderatorID string, userID string, reason string) error
	StartRaid(ctx context.Context, fromBroadcasterID string, toBroadcasterID string) (twitchapi.RaidData, error)
	CancelRaid(ctx context.Context, broadcasterID string) error
	SendShoutout(ctx context.Context, fromBroadcasterID string, toBroadcasterID string, moderatorID string) error
	ManageAutoModMessage(ctx context.Context, userID string, messageID string, action string) error
	SnoozeNextAd(ctx context.Context, broadcasterID string) (twitchapi.AdSnoozeData, error)
	FetchUnbanRequests(ctx context.Context, broadcasterID string, moderatorID string) ([]twitchapi.UnbanRequest, error)
	ResolveBanRequest(ctx context.Context, broadcasterID string, moderatorID string, requestID string, status string, resolutionText string) (twitchapi.UnbanRequest, error)
}

ModerationAPI is the moderation surface of a Twitch client.

type RecentMessageService

type RecentMessageService interface {
	GetRecentMessagesFor(ctx context.Context, channelLogin string) ([]twitchirc.IRCer, error)
}

type ReplyTarget

type ReplyTarget struct {
	MessageID   string
	DisplayName string
	Snippet     string
}

ReplyTarget is the message the next send answers. It is plain data so the composer never needs an entry handle or the transcript.

type RequestLocalMessageHandleBatchMessage

type RequestLocalMessageHandleBatchMessage struct {
	Messages  []twitchirc.IRCer
	AccountID string
	TabID     string
}

RequestLocalMessageHandleBatchMessage is the same as RequestLocalMessageHandleMessage but for multiple messages.

type RequestLocalMessageHandleMessage

type RequestLocalMessageHandleMessage struct {
	Message   twitchirc.IRCer
	AccountID string
	TabID     string
}

RequestLocalMessageHandleMessage comes when the program requests a message to be handled by the IRC message handler which then converts it into a ChatEventMessage.

type RequestNotificationIconMessage

type RequestNotificationIconMessage struct {
	TabID string
}

RequestNotificationIconMessage comes when app requests an notification icon for a tab.

type SetStreamInfoMessage

type SetStreamInfoMessage struct {
	Target   string // the broadcasters ID
	Username string // is broadcasters display name
	Viewer   int
	Title    string
	Game     string
	IsLive   bool
}

SetStreamInfoMessage comes when new live info about a streamer was fetched.

type Submission

type Submission struct {
	Text    string
	ReplyTo string
}

Submission is what the composer hands to the tab when the user sends. The tab decides whether the text is a slash command or a chat message and whether the account may send at all.

type SuggestionConfig

type SuggestionConfig struct {
	Channels                 []string
	Emotes                   []string
	IncludeModeratorCommands bool
	KeyMap                   save.KeyMap
}

SuggestionConfig is the complete suggestion state. Configure applies it in one call so the composer cannot hold a half-updated mix of channels, emotes, moderator commands and key bindings.

type Tab

type Tab interface {
	Init() tea.Cmd
	InitWithUserData(twitchapi.UserData) tea.Cmd
	Update(tea.Msg) (Tab, tea.Cmd)
	View() string
	ViewWithoutStatusBar() string // body-only rendering, with Root's shared status line
	StatusBarView() string        // status at full terminal width
	Focus()
	Blur()
	Close() // release whatever the tab started; safe on tabs that own nothing
	AccountID() string
	Channel() string
	IsComposing() bool // a text input inside the tab is capturing printable keys
	IsSearching() bool
	IsDataLoaded() bool
	ID() string
	Focused() bool
	ChannelID() string
	HandleResize()
	SetSize(width, height int)
	SetFullWidth(width int) // nonzero when Root renders the status outside this tab
	Kind() TabKind
	Title() string    // header label, e.g. the channel name
	Identity() string // account label shown next to the title
}

Tab is what the shell needs from a tab: lifecycle, layout, identity, and the few questions Root asks while deciding what an input event means.

type TabKind

type TabKind int

TabKind is the set of tab implementations a session can open.

const (
	BroadcastKind TabKind = iota
	MentionKind
	LiveNotificationKind
)

func (TabKind) String

func (t TabKind) String() string

type ThemeChangedMessage

type ThemeChangedMessage struct {
	Theme save.Theme
}

ThemeChangedMessage tells a tab that the user selected a different theme.

Tabs are not rebuilt on a theme switch: they re-derive the styles they cached at construction and re-render their transcripts. Everything else — drafts, scroll positions, filters, focus, in-flight requests — stays untouched, so a theme switch is invisible apart from the colors.

type UserAuthenticatedAPI

type UserAuthenticatedAPI interface {
	CreateClip(ctx context.Context, broadcastID string, hasDelay bool) (twitchapi.CreatedClip, error)
	GetUserChatColor(ctx context.Context, userIDs []string) ([]twitchapi.UserChatColor, error)
	SendChatMessage(ctx context.Context, data twitchapi.SendChatMessageRequest) (twitchapi.SendChatMessageResponse, error)
}

UserAuthenticatedAPI is the part of a Twitch client that only works with the account's own token: sending messages, making clips, reading chat colours.

type UserEmoteClient

type UserEmoteClient interface {
	FetchAllUserEmotes(ctx context.Context, userID string, broadcasterID string) ([]twitchapi.UserEmoteImage, string, error)
}

Jump to

Keyboard shortcuts

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