Documentation
¶
Overview ¶
Package shared provides common UI components for the OpenCode TUI, including modals, spinners, and icon constants.
Package shared provides common UI components for the OpenCode TUI, including modals, spinners, and icon constants.
Package shared provides common UI components for the OpenCode TUI, including modals, spinners, and icon constants.
Index ¶
- Constants
- Variables
- func GetFileIcon(filename string) string
- func GetIcon(name string) string
- func SimpleSpinner() string
- func SimpleSpinnerWithMessage(message string) string
- type ModalModel
- type ModalMsg
- type ModalOption
- type ModalRenderer
- type SpinnerFrame
- type SpinnerModel
- type SpinnerRenderer
- type SpinnerTickMsg
Constants ¶
const ( // OpenCode specific icons IconOpenCode = "⌬" // OpenCode logo icon // General UI Icons IconCheck = "✓" // Checkmark / success IconCheckAlt = "✓" // Checkmark alternative IconError = "✖" // Error / close IconErrorAlt = "✗" // Error alternative / failure IconWarning = "⚠" // Warning indicator IconInfo = "ℹ" // Information IconHint = "💡" // Hint / tip IconHintAlt = "i" // Hint alternative (simple) IconQuestion = "❓" // Question mark IconStar = "★" // Star / favorite IconStarOutline = "☆" // Star outline IconHeart = "♥" // Heart IconHeartOutline = "♡" // Heart outline IconLightning = "⚡" // Lightning bolt IconPlug = "🔌" // Plug / power IconTool = "🛠️" // Tool / wrench // Navigation Icons IconArrowRight = "→" // Arrow right IconArrowLeft = "←" // Arrow left IconArrowUp = "↑" // Arrow up IconArrowDown = "↓" // Arrow down IconChevronRight = "›" // Chevron right IconChevronLeft = "‹" // Chevron left IconChevronUp = "⌃" // Chevron up IconChevronDown = "⌄" // Chevron down IconCaretDown = "▼" IconCaretRight = "▶" IconStatusDot = "●" // File and Folder Icons IconFolder = "📁" // Folder IconFolderOpen = "📂" // Open folder IconFile = "📄" // Generic file IconDocument = "📝" // Document IconImage = "🖼" // Image file IconCode = "💻" // Code file IconDatabase = "🗄" // Database IconArchive = "📦" // Archive / zip // Action Icons IconSearch = "🔍" // Search IconZoomIn = "🔎" // Zoom in IconZoomOut = "🔍" // Zoom out IconEdit = "✏" // Edit IconPencil = "✎" // Pencil IconCopy = "📋" // Copy IconCut = "✂" // Cut IconPaste = "📌" // Paste IconTrash = "🗑" // Delete / trash IconSave = "💾" // Save IconDownload = "⬇" // Download IconUpload = "⬆" // Upload IconRefresh = "⟳" // Refresh / reload IconSync = "🔄" // Sync IconSettings = "⚙" // Settings / gear IconCog = "⚙" // Settings (alternative) IconPlus = "+" // Add / plus IconMinus = "−" // Remove / minus IconClose = "✕" // Close IconMenu = "☰" // Menu / hamburger IconList = "☰" // List view // Status Icons IconPlay = "▶" // Play IconPause = "⏸" // Pause IconStop = "⏹" // Stop IconRecord = "⏺" // Record IconRewind = "⏪" // Rewind IconFastForward = "⏩" // Fast forward IconSkipBack = "⏮" // Skip back IconSkipForward = "⏭" // Skip forward // Chat and Message Icons IconMessage = "💬" // Speech bubble IconMessageOutline = "💭" // Thought bubble IconBot = "🤖" // Bot / robot IconUser = "👤" // User IconUsers = "👥" // Users group IconPerson = "🧑" // Person IconSend = "➤" // Send IconMail = "✉" // Email / mail // Technology Icons IconTerminal = "⌨" // Terminal IconCommand = "⌘" // Command / cmd IconKey = "⌥" // Option / alt key IconKeyboard = "⌨" // Keyboard IconLink = "🔗" // Link / hyperlink IconLinkBroken = "🔗" // Broken link IconLock = "🔒" // Lock / locked IconLockOpen = "🔓" // Unlock / unlocked IconWifi = "📶" // WiFi signal IconSignal = "📡" // Signal IconBluetooth = "📘" // Bluetooth // Development Icons IconBug = "🐛" // Bug IconCommit = "⬤" // Commit / dot IconBranch = "⎇" // Branch IconGit = "⎇" // Git branch IconMerge = "⇄" // Merge IconPullRequest = "⇄" // Pull request IconIssue = "⚠" // Issue / warning IconPullDown = "⇩" // Pull down // Time and Date Icons IconClock = "🕐" // Clock IconTime = "🕒" // Time IconCalendar = "📅" // Calendar IconAlarm = "⏰" // Alarm // Misc Icons IconLightbulb = "💡" // Lightbulb / idea IconMagic = "✨" // Sparkles / magic IconFire = "🔥" // Fire / hot IconRocket = "🚀" // Rocket IconDiamond = "💎" // Diamond / gem IconTrophy = "🏆" // Trophy IconMedal = "🏅" // Medal IconCrown = "👑" // Crown IconGem = "💠" // Gem / diamond // Loading/Progress Icons IconSpinner = "⟳" // Spinner / loading IconLoading = "⏳" // Hourglass / loading IconHourglass = "⏳" // Hourglass IconCircle = "⬤" // Circle / dot // Nerd Fonts Dev Icons (alternative with NF specific glyphs) // These are the proper Nerd Fonts versions if available NFArrowRight = "→" NFArrowLeft = "←" NFArrowUp = "↑" NFArrowDown = "↓" NFChevronRight = "›" NFChevronLeft = "‹" NFClose = "✕" NFCheck = "✓" NFError = "✗" NFStar = "★" NFStarOutline = "☆" NFTerminal = "⌨" NFCode = "⌘" NFKey = "⌥" NFGitBranch = "⎇" NFGitCommit = "⬤" NFConfig = "⚙" NFSettings = "⚙" NFSearch = "🔍" NFRefresh = "⟳" NFSpinner = "⠄" )
Icon constants using Nerd Fonts glyphs for consistent UI icons. These icons are used throughout the TUI for visual indicators.
Variables ¶
var ( // StatusIcons contains icons for different status states StatusIcons = map[string]string{ "success": IconCheck, "error": IconError, "warning": IconWarning, "info": IconInfo, "loading": IconSpinner, "pending": IconClock, "complete": IconCheck, } // FileTypeIcons maps file extensions to their corresponding icons FileTypeIcons = map[string]string{ "go": IconCode, "js": IconCode, "ts": IconCode, "py": IconCode, "rs": IconCode, "java": IconCode, "c": IconCode, "cpp": IconCode, "h": IconCode, "hpp": IconCode, "md": IconDocument, "txt": IconDocument, "json": IconCode, "yaml": IconCode, "yml": IconCode, "toml": IconCode, "png": IconImage, "jpg": IconImage, "jpeg": IconImage, "gif": IconImage, "svg": IconImage, "zip": IconArchive, "tar": IconArchive, "gz": IconArchive, "db": IconDatabase, "sql": IconDatabase, } // ActionIcons contains icons for user actions ActionIcons = map[string]string{ "add": IconPlus, "remove": IconMinus, "edit": IconEdit, "delete": IconTrash, "save": IconSave, "search": IconSearch, "copy": IconCopy, "paste": IconPaste, "cut": IconCut, "refresh": IconRefresh, "settings": IconSettings, "close": IconClose, "menu": IconMenu, "download": IconDownload, "upload": IconUpload, } )
IconSet provides a categorized set of icons for specific UI contexts.
var ( // SpinnerFrames holds the animation frames for a spinner. SpinnerFrames = []SpinnerFrame{ "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏", } // DotsSpinnerFrames is an alternative dots-style spinner. DotsSpinnerFrames = []SpinnerFrame{ "⠁", "⠂", "⠄", "⡀", "⠈", "⠐", "⠠", "⠰", "⠸", "⠧", } // LineSpinnerFrames is a simple line spinner. LineSpinnerFrames = []SpinnerFrame{ "|", "/", "−", "\\", } )
Spinner frames using Unicode characters for smooth animation.
var ModalRendererInstance = NewModalRenderer()
ModalRendererInstance is a global instance for convenient modal rendering.
var SpinnerRendererInstance = NewSpinnerRenderer()
SpinnerRendererInstance is a global instance for convenient spinner rendering.
Functions ¶
func GetFileIcon ¶
GetFileIcon returns the appropriate icon for a file based on its extension.
func SimpleSpinner ¶
func SimpleSpinner() string
SimpleSpinner renders a simple spinner without state management. Useful for one-off rendering in UI components.
func SimpleSpinnerWithMessage ¶
SimpleSpinnerWithMessage renders a simple spinner with a message.
Types ¶
type ModalModel ¶
type ModalModel struct {
Title string
Content string
Width int
Height int
Focused bool
ShowClose bool
Buttons []string
Selected int
// contains filtered or unexported fields
}
ModalModel implements the tea.Model interface for modal dialogs.
func NewModalModel ¶
func NewModalModel(title, content string, opts ...ModalOption) ModalModel
NewModalModel creates a new ModalModel with the given options.
func (*ModalModel) SetResultChannel ¶
func (m *ModalModel) SetResultChannel(ch chan<- ModalMsg)
SetResultChannel sets the channel to receive modal results.
type ModalOption ¶
type ModalOption func(*modalConfig)
ModalOption is a functional option for configuring modal styles.
func WithModalCloseButton ¶
func WithModalCloseButton(show bool) ModalOption
WithModalCloseButton shows or hides the close button.
func WithModalFocused ¶
func WithModalFocused(focused bool) ModalOption
WithModalFocused sets the focused state for the modal.
func WithModalHeight ¶
func WithModalHeight(height int) ModalOption
WithModalHeight sets the height for the modal.
func WithModalTitle ¶
func WithModalTitle(title string) ModalOption
WithModalTitle sets the title for the modal.
func WithModalWidth ¶
func WithModalWidth(width int) ModalOption
WithModalWidth sets the width for the modal.
type ModalRenderer ¶
type ModalRenderer struct{}
ModalRenderer provides methods to render modal dialogs.
func NewModalRenderer ¶
func NewModalRenderer() *ModalRenderer
NewModalRenderer creates a new ModalRenderer instance.
func (*ModalRenderer) ConfirmModal ¶
func (r *ModalRenderer) ConfirmModal(message string, opts ...ModalOption) string
ConfirmModal renders a confirmation modal with OK and Cancel buttons.
func (*ModalRenderer) InputModal ¶
func (r *ModalRenderer) InputModal(message, placeholder string, opts ...ModalOption) string
InputModal renders a modal with an input field.
func (*ModalRenderer) Render ¶
func (r *ModalRenderer) Render(content string, opts ...ModalOption) string
Render renders a modal with the given content.
type SpinnerFrame ¶
type SpinnerFrame string
SpinnerFrame represents a single frame in the spinner animation.
type SpinnerModel ¶
type SpinnerModel struct {
// contains filtered or unexported fields
}
SpinnerModel implements the tea.Model interface for animated spinners.
func NewSpinnerModel ¶
func NewSpinnerModel(message string) SpinnerModel
NewSpinnerModel creates a new SpinnerModel with the given message.
func NewSpinnerModelWithFrames ¶
func NewSpinnerModelWithFrames(message string, frames []SpinnerFrame, interval time.Duration) SpinnerModel
NewSpinnerModelWithFrames creates a new SpinnerModel with custom frames.
func (SpinnerModel) Init ¶
func (m SpinnerModel) Init() tea.Cmd
Init implements tea.Model Init method.
func (*SpinnerModel) SetMessage ¶
func (m *SpinnerModel) SetMessage(msg string)
SetMessage updates the spinner's message.
func (SpinnerModel) Tick ¶
func (m SpinnerModel) Tick() tea.Cmd
Tick returns a command that waits for the interval and sends a SpinnerTickMsg.
func (SpinnerModel) View ¶
func (m SpinnerModel) View() string
View implements tea.Model View method.
type SpinnerRenderer ¶
type SpinnerRenderer struct {
// contains filtered or unexported fields
}
SpinnerRenderer provides methods to render loading spinners.
func NewSpinnerRenderer ¶
func NewSpinnerRenderer() *SpinnerRenderer
NewSpinnerRenderer creates a new SpinnerRenderer with default settings.
func NewSpinnerRendererWithFrames ¶
func NewSpinnerRendererWithFrames(frames []SpinnerFrame, interval time.Duration) *SpinnerRenderer
NewSpinnerRendererWithFrames creates a new SpinnerRenderer with custom frames.
func (*SpinnerRenderer) Interval ¶
func (s *SpinnerRenderer) Interval() time.Duration
Interval returns the interval between frames.
func (*SpinnerRenderer) NextFrame ¶
func (s *SpinnerRenderer) NextFrame() SpinnerFrame
NextFrame advances to the next frame and returns the current frame.
func (*SpinnerRenderer) Render ¶
func (s *SpinnerRenderer) Render() string
Render returns the current spinner frame as a styled string.
func (*SpinnerRenderer) RenderWithMessage ¶
func (s *SpinnerRenderer) RenderWithMessage(message string) string
RenderWithMessage returns the spinner with a message.
func (*SpinnerRenderer) Reset ¶
func (s *SpinnerRenderer) Reset()
Reset resets the spinner to the first frame.
func (*SpinnerRenderer) Tick ¶
func (s *SpinnerRenderer) Tick() tea.Cmd
Tick is a command that waits for the spinner interval and sends a message. This enables chaining the animation in the Update loop.
type SpinnerTickMsg ¶
type SpinnerTickMsg struct{}