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 ¶
- Variables
- func Caption(kind TabKind, account save.Account, channel string) (title, identity string)
- func ExtractValidURLs(text string) []string
- func NewEmoteOverview(channelID string, cache EmoteCache, replacer EmoteReplacer, ...) *emoteOverview
- func NewLiveNotification(id string, width, height int, settings save.Settings, theme save.Theme, ...) *liveNotificationTab
- func NewMention(id string, width, height int, settings save.Settings, theme save.Theme, ...) *mentionTab
- func WheelDelta(msg tea.MouseWheelMsg) int
- type APIClient
- type AccountProvider
- type BadgeReplacer
- type Broadcast
- func (t *Broadcast) AccountID() string
- func (t *Broadcast) Blur()
- func (t *Broadcast) Channel() string
- func (t *Broadcast) ChannelID() string
- func (t *Broadcast) Close()
- func (t *Broadcast) Focus()
- func (t *Broadcast) Focused() bool
- func (t *Broadcast) HandleMouseClick(msg tea.MouseClickMsg, x, y int) tea.Cmd
- func (t *Broadcast) HandleMouseLeave()
- func (t *Broadcast) HandleMouseMotion(x, y int)
- func (t *Broadcast) HandleMouseWheel(msg tea.MouseWheelMsg, x, y int) tea.Cmd
- func (t *Broadcast) HandleResize()
- func (t *Broadcast) ID() string
- func (t *Broadcast) Identity() string
- func (t *Broadcast) Init() tea.Cmd
- func (t *Broadcast) InitWithUserData(userData twitchapi.UserData) tea.Cmd
- func (t *Broadcast) IsComposing() bool
- func (t *Broadcast) IsDataLoaded() bool
- func (t *Broadcast) IsSearching() bool
- func (t *Broadcast) Kind() TabKind
- func (t *Broadcast) LocalSubOnly() bool
- func (t *Broadcast) LocalUniqueOnly() bool
- func (t *Broadcast) SetFullWidth(width int)
- func (t *Broadcast) SetLocalSubOnly(v bool)
- func (t *Broadcast) SetLocalUniqueOnly(v bool)
- func (t *Broadcast) SetSize(width, height int)
- func (t *Broadcast) SetTheme(theme save.Theme)
- func (t *Broadcast) SetUpdateAvailable(latest string)
- func (t *Broadcast) StatusBarView() string
- func (t *Broadcast) Title() string
- func (t *Broadcast) Update(msg tea.Msg) (Tab, tea.Cmd)
- func (t *Broadcast) View() string
- func (t *Broadcast) ViewWithoutStatusBar() string
- type ChannelSuggestionsLoadedMessage
- type ClientCapabilities
- type ConnectionPool
- type EmoteCache
- type EmoteReplacer
- type FollowedChannelsAPI
- type JoinChannelMessage
- type MessageLogger
- type ModStatusFetcher
- type ModerationAPI
- type RecentMessageService
- type ReplyTarget
- type RequestLocalMessageHandleBatchMessage
- type RequestLocalMessageHandleMessage
- type RequestNotificationIconMessage
- type SetStreamInfoMessage
- type Submission
- type SuggestionConfig
- type Tab
- type TabKind
- type ThemeChangedMessage
- type UserAuthenticatedAPI
- type UserEmoteClient
Constants ¶
This section is empty.
Variables ¶
var LoadingSpinner = spinner.Points
LoadingSpinner is the unified spinner used across all loading states.
Functions ¶
func Caption ¶
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 NewEmoteOverview ¶
func NewEmoteOverview(channelID string, cache EmoteCache, replacer EmoteReplacer, graphicRows, width, height int) *emoteOverview
func NewLiveNotification ¶
func NewMention ¶
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 BadgeReplacer ¶
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) HandleMouseClick ¶
func (*Broadcast) HandleMouseLeave ¶
func (t *Broadcast) HandleMouseLeave()
HandleMouseLeave clears the emote tooltip.
func (*Broadcast) HandleMouseMotion ¶
HandleMouseMotion records the pointer position (tab-local) for the emote tooltip.
func (*Broadcast) HandleMouseWheel ¶
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) InitWithUserData ¶
func (*Broadcast) IsComposing ¶
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 (*Broadcast) IsSearching ¶
func (*Broadcast) LocalSubOnly ¶
LocalSubOnly reports whether the tab drops non-subscriber messages locally.
func (*Broadcast) LocalUniqueOnly ¶
LocalUniqueOnly reports whether the tab drops repeated messages locally.
func (*Broadcast) SetFullWidth ¶
func (*Broadcast) SetLocalSubOnly ¶
SetLocalSubOnly restores that filter when a session is reloaded.
func (*Broadcast) SetLocalUniqueOnly ¶
SetLocalUniqueOnly restores that filter when a session is reloaded.
func (*Broadcast) SetUpdateAvailable ¶
SetUpdateAvailable makes the status bar advertise a newer version. An empty version clears the notice.
func (*Broadcast) StatusBarView ¶
StatusBarView returns the status bar for Root's shared status line.
func (*Broadcast) ViewWithoutStatusBar ¶
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 FollowedChannelsAPI ¶
type FollowedChannelsAPI interface {
FetchUserFollowedChannels(ctx context.Context, userID string, broadcasterID string) ([]twitchapi.FollowedChannel, error)
}
FollowedChannelsAPI lists the channels an account follows.
type JoinChannelMessage ¶
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 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 ReplyTarget ¶
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 ¶
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 ThemeChangedMessage ¶
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.