common

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderHeight is the height of the header bar (single line with Inline(true))
	HeaderHeight = 1

	// HeaderNewline is the newline added after the header in View()
	HeaderNewline = 1

	// FooterHeight is the height of the help/footer text
	FooterHeight = 1

	// PanelMarginVertical is the vertical margin applied to each panel (Margin(1) = 1 top + 1 bottom)
	PanelMarginVertical = 2

	// PanelMarginLeft is the left margin applied to panels (MarginLeft(1))
	PanelMarginLeft = 1

	// BorderWidth is the width of a normal border (1 char on each side)
	BorderWidth = 1

	// TwoPanelBorderWidth is total horizontal space taken by borders when two panels are shown
	// Left panel: hidden border (1) + right edge (1) = 2
	// Right panel: left edge (1) + right edge (1) = 2
	// Total = 4
	TwoPanelBorderWidth = 4

	// TwoPanelMarginWidth is total horizontal space taken by margins for two panels
	// Left panel margin (1) + right panel margin (1) = 2
	TwoPanelMarginWidth = 2

	// HeaderSidePadding is the padding on each side of the header (2 spaces each side)
	HeaderSidePadding = 2

	// DefaultItemHeight is the estimated height of a single list item in lines
	DefaultItemHeight = 3

	// MinItemsPerPage is the minimum number of items to show per page
	MinItemsPerPage = 3

	// DefaultItemsPerPage is used when dynamic calculation isn't possible
	DefaultItemsPerPage = 10

	// HeaderTotalPadding is the total horizontal padding for header content (2 spaces each side)
	// Used in header.go for spacing calculation: width - totalTextLen - 4
	HeaderTotalPadding = 4

	// CreateUserDialogMargin is the horizontal margin for the create user dialog
	// Style.Margin(0, 3) = 3 chars on each side = 6, plus border (2) = 8
	CreateUserDialogBorderAndMargin = 8

	// CreateUserMinWidth is the minimum width for the create user dialog
	CreateUserMinWidth = 40

	// TextInputDefaultWidth is a reasonable default width for text input fields
	TextInputDefaultWidth = 30

	// MaxContentTruncateWidth is the maximum width for truncating post content
	// This prevents very long lines on wide terminals
	MaxContentTruncateWidth = 150

	// ReplyIndentWidth is the number of spaces used to indent replies in thread view
	ReplyIndentWidth = 4

	// TimelineRefreshSeconds is the interval for auto-refreshing timeline views
	TimelineRefreshSeconds = 10

	// HomeTimelinePostLimit is the maximum number of posts to load in home timeline
	HomeTimelinePostLimit = 50

	// MaxNoteDBLength is the maximum character length for notes in the database
	MaxNoteDBLength = 1000

	// HoursPerDay is used for time formatting calculations
	HoursPerDay = 24

	// MaxDisplayContentLength is the maximum characters to display for note content
	// Users can press 'o' to view full content via original link
	MaxDisplayContentLength = 1000
)
View Source
const (
	// === Primary UI Colors ===
	COLOR_ACCENT    = "69" // ANSI 69 (#5f87ff) - Primary accent: borders, selections, header
	COLOR_SECONDARY = "75" // ANSI 75 (#5fafff) - Secondary accent: timestamps, domains, hashtags

	// === Text Colors ===
	COLOR_WHITE = "255" // ANSI 255 (#eeeeee) - Primary text, post content
	COLOR_LIGHT = "250" // ANSI 250 (#bcbcbc) - Secondary text, slightly dimmed
	COLOR_MUTED = "245" // ANSI 245 (#8a8a8a) - Tertiary text, disabled, hints
	COLOR_DIM   = "240" // ANSI 240 (#585858) - Very dim text, borders, separators

	// === Semantic Colors ===
	COLOR_USERNAME = "48"  // ANSI 48 (#00ff87) - Usernames stand out
	COLOR_SUCCESS  = "48"  // ANSI 48 (#00ff87) - Success messages (same as username for cohesion)
	COLOR_ERROR    = "196" // ANSI 196 (#ff0000) - Errors, delete actions, warnings
	COLOR_CRITICAL = "9"   // ANSI 9 (#ff5555) - Critical errors, terminal size warnings
	COLOR_WARNING  = "214" // ANSI 214 (#ffaf00) - Content warnings, caution (amber)

	// === Interactive Elements ===
	COLOR_HASHTAG = "75"  // ANSI 75 (#5fafff) - Hashtags (same as secondary for harmony)
	COLOR_MENTION = "48"  // ANSI 48 (#00ff87) - Mentions (same as username for consistency)
	COLOR_LINK    = "48"  // ANSI 48 (#00ff87) - Hyperlinks (same as username/mention)
	COLOR_BUTTON  = "117" // ANSI 117 (#87d7ff) - Button highlights, active elements

	// === Section/Title Colors ===
	COLOR_CAPTION = "170" // ANSI 170 (#d75fd7) - Section captions, titles
	COLOR_HELP    = "245" // ANSI 245 (#8a8a8a) - Help text (same as muted)

	// === Background Colors ===
	COLOR_BLACK = "0" // ANSI 0 (#000000) - Button text on light backgrounds

	// === OSC8 Hyperlink Colors (RGB format for true color terminals) ===
	COLOR_LINK_RGB    = "0;255;135" // RGB for hyperlinks (#00ff87) - matches COLOR_LINK
	COLOR_MENTION_RGB = "0;255;135" // RGB for mentions (#00ff87) - matches COLOR_MENTION

	// === ANSI Escape Sequences (for inline coloring without breaking backgrounds) ===
	ANSI_WARNING_START = "\033[38;5;214m" // Start warning color (orange/yellow)
	ANSI_COLOR_RESET   = "\033[39m"       // Reset foreground to default

	// === Deprecated aliases (for backwards compatibility during transition) ===
	// These will be removed in a future version - use the semantic names above
	COLOR_GREY        = COLOR_MUTED     // Use COLOR_MUTED instead
	COLOR_MAGENTA     = COLOR_CAPTION   // Use COLOR_CAPTION instead
	COLOR_LIGHTBLUE   = COLOR_ACCENT    // Use COLOR_ACCENT instead
	COLOR_GREEN       = COLOR_USERNAME  // Use COLOR_USERNAME instead
	COLOR_BLUE        = COLOR_SECONDARY // Use COLOR_SECONDARY instead
	COLOR_DARK_GREY   = COLOR_DIM       // Use COLOR_DIM instead
	COLOR_BORDER_GREY = COLOR_DIM       // Use COLOR_DIM instead
	COLOR_RED         = COLOR_ERROR     // Use COLOR_ERROR instead
	COLOR_CYAN        = COLOR_BUTTON    // Use COLOR_BUTTON instead
	COLOR_BRIGHT_RED  = COLOR_CRITICAL  // Use COLOR_CRITICAL instead
)
View Source
const (
	// ListSelectedPrefix is the indicator shown before selected items
	ListSelectedPrefix = "› "
	// ListUnselectedPrefix is the spacing for unselected items (same width as selected)
	ListUnselectedPrefix = "  "
)
View Source
const (
	TermsDialogBorderAndMargin = 8  // 2 (border) + 6 (margins)
	TermsDialogMinWidth        = 60 // Minimum width for terms dialog
)

Terms and Conditions dialog constants

View Source
const (
	// DeleteAccountView is deprecated, use AccountSettingsView
	DeleteAccountView = AccountSettingsView
)

Variables

View Source
var (
	HelpStyle    = lipgloss.NewStyle().Foreground(lipgloss.Color(COLOR_GREY)).Padding(0, 2)
	CaptionStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(COLOR_MAGENTA)).Padding(2)

	// ListItemStyle is the base style for unselected list items
	ListItemStyle = lipgloss.NewStyle()

	// ListItemSelectedStyle is for the selected item text (highlighted color + bold)
	ListItemSelectedStyle = lipgloss.NewStyle().
							Foreground(lipgloss.Color(COLOR_USERNAME)).
							Bold(true)

	// ListEmptyStyle is for empty list messages
	ListEmptyStyle = lipgloss.NewStyle().
					Foreground(lipgloss.Color(COLOR_DIM)).
					Italic(true)

	// ListStatusStyle is for status messages (success, info)
	ListStatusStyle = lipgloss.NewStyle().
					Foreground(lipgloss.Color(COLOR_SUCCESS))

	// ListErrorStyle is for error messages
	ListErrorStyle = lipgloss.NewStyle().
					Foreground(lipgloss.Color(COLOR_ERROR))

	// ListBadgeStyle is for inline badges like [local], [pending], [ADMIN]
	ListBadgeStyle = lipgloss.NewStyle().
					Foreground(lipgloss.Color(COLOR_DIM))

	// ListBadgeMutedStyle is for muted user badge
	ListBadgeMutedStyle = lipgloss.NewStyle().
						Foreground(lipgloss.Color(COLOR_ERROR))

	// ListBadgeEnabledStyle is for enabled/active status badges
	ListBadgeEnabledStyle = lipgloss.NewStyle().
							Foreground(lipgloss.Color(COLOR_SUCCESS))
)

Functions

func CalculateAvailableHeight added in v1.4.0

func CalculateAvailableHeight(totalHeight int) int

CalculateAvailableHeight returns the height available for panel content after accounting for header, footer, and panel margins

func CalculateContentWidth added in v1.4.0

func CalculateContentWidth(panelWidth, padding int) int

CalculateContentWidth returns the width for content inside a panel after accounting for internal padding

func CalculateItemsPerPage added in v1.4.0

func CalculateItemsPerPage(availableHeight, itemHeight int) int

CalculateItemsPerPage returns the number of items that fit in the available height based on the estimated item height

func CalculateLeftPanelWidth added in v1.4.0

func CalculateLeftPanelWidth(totalWidth int) int

CalculateLeftPanelWidth returns the width for the left panel (1/3 of total)

func CalculateRightPanelWidth added in v1.4.0

func CalculateRightPanelWidth(totalWidth, leftPanelWidth int) int

CalculateRightPanelWidth returns the width for the right panel after accounting for left panel width and borders/margins

func DefaultCreateNoteWidth

func DefaultCreateNoteWidth(width int) int

func DefaultListHeight

func DefaultListHeight(height int) int

func DefaultListWidth

func DefaultListWidth(width int) int

func DefaultWindowHeight

func DefaultWindowHeight(heigth int) int

DefaultWindowHeight returns the usable height after accounting for outer margins The offset of 10 accounts for: outer margins (2*2=4) + potential terminal chrome (6)

func DefaultWindowWidth

func DefaultWindowWidth(width int) int

DefaultWindowWidth returns the usable width after accounting for outer margins The offset of 10 accounts for: outer margins (2*2=4) + potential scrollbar (2) + safety buffer (4)

func HorizontalPanelOffset added in v1.4.0

func HorizontalPanelOffset() int

HorizontalPanelOffset returns the total horizontal space taken by borders and margins when rendering two side-by-side panels

func MeasureHeight added in v1.4.0

func MeasureHeight(rendered string) int

MeasureHeight returns the height of a rendered string using lipgloss

func MeasureWidth added in v1.4.0

func MeasureWidth(rendered string) int

MeasureWidth returns the width of a rendered string using lipgloss

func VerticalLayoutOffset added in v1.4.0

func VerticalLayoutOffset() int

VerticalLayoutOffset returns the total vertical space taken by header, footer, and margins Use this to calculate available height for panel content

Types

type ActivateAccountSettingsMsg added in v1.6.2

type ActivateAccountSettingsMsg struct{}

ActivateAccountSettingsMsg is sent specifically to accountsettings when it becomes visible This avoids conflicts with the generic ActivateViewMsg used by timeline views

type ActivateViewMsg added in v1.3.0

type ActivateViewMsg struct{}

ActivateViewMsg is sent when a view becomes active (visible)

type BoostNoteMsg added in v1.6.0

type BoostNoteMsg struct {
	NoteURI string    // ActivityPub object URI of the note being boosted
	NoteID  uuid.UUID // Local UUID (if local note)
	IsLocal bool      // Whether this is a local note
}

BoostNoteMsg is sent when user presses 'b' to boost/unboost a post

type DeactivateAccountSettingsMsg added in v1.6.2

type DeactivateAccountSettingsMsg struct{}

DeactivateAccountSettingsMsg is sent specifically to accountsettings when it becomes hidden

type DeactivateViewMsg added in v1.3.0

type DeactivateViewMsg struct{}

DeactivateViewMsg is sent when a view becomes inactive (hidden)

type DeleteNoteMsg

type DeleteNoteMsg struct {
	NoteId uuid.UUID
}

DeleteNoteMsg is sent when user confirms note deletion

type EditNoteMsg

type EditNoteMsg struct {
	NoteId    uuid.UUID
	Message   string
	CreatedAt time.Time
}

EditNoteMsg is sent when user wants to edit an existing note

type LikeNoteMsg added in v1.4.1

type LikeNoteMsg struct {
	NoteURI string    // ActivityPub object URI of the note being liked
	NoteID  uuid.UUID // Local UUID (if local note)
	IsLocal bool      // Whether this is a local note
}

LikeNoteMsg is sent when user presses 'l' to like/unlike a post

type ReplyToNoteMsg added in v1.4.0

type ReplyToNoteMsg struct {
	NoteURI string // ActivityPub object URI of the note being replied to
	Author  string // Display name or handle of the author
	Preview string // Preview of the note content (first line or truncated)
}

ReplyToNoteMsg is sent when user presses 'r' to reply to a post

type SessionState

type SessionState uint
const (
	CreateNoteView   SessionState = iota
	HomeTimelineView              // Unified home timeline (local + remote)
	MyPostsView                   // View only your own posts
	GlobalPostsView               // Global timeline (all local + all federated posts)
	CreateUserView
	UpdateNoteList
	FollowUserView      // Follow remote users
	FollowersView       // View who follows you
	FollowingView       // View who you're following
	LocalUsersView      // Browse and follow local users
	AdminPanelView      // Admin panel for user management (admin only)
	RelayManagementView // Admin panel for relay management (admin only)
	AccountSettingsView // Account settings (profile, avatar, delete)
	ThreadView          // View thread with parent and replies
	NotificationsView   // View notifications
	ProfileView         // View user profile with recent posts
	TermsAcceptanceView // Terms acceptance for existing users
)

type ViewProfileMsg added in v1.6.2

type ViewProfileMsg struct {
	Username  string
	AccountId uuid.UUID
	IsRemote  bool   // true for remote/federated users
	ActorURI  string // ActivityPub actor URI for remote users
	Domain    string // domain for display (e.g., "mastodon.social")
}

ViewProfileMsg is sent when user presses Enter on a user to view their profile

type ViewThreadMsg added in v1.4.0

type ViewThreadMsg struct {
	NoteURI   string    // ActivityPub object URI of the note
	NoteID    uuid.UUID // Local UUID (if local note)
	IsLocal   bool      // Whether this is a local note
	Author    string    // Author name for display
	Content   string    // Full content
	CreatedAt time.Time // Timestamp
}

ViewThreadMsg is sent when user presses Enter to view a thread

Jump to

Keyboard shortcuts

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