common

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const MaxAttachmentSize = int64(5 * 1024 * 1024)

MaxAttachmentSize defines the maximum allowed size for file attachments (5 MB).

Variables

View Source
var AllowedImageTypes = []string{".jpg", ".jpeg", ".png"}

AllowedImageTypes defines the permitted image file types.

Functions

func BottomLeftRect

func BottomLeftRect(area uv.Rectangle, width, height int) uv.Rectangle

BottomLeftRect returns a new [Rectangle] positioned at the bottom-left within the given area with the specified width and height.

func Button

func Button(t *styles.Styles, opts ButtonOpts) string

Button creates a button with an underlined character and selection state

func ButtonGroup

func ButtonGroup(t *styles.Styles, buttons []ButtonOpts, spacing string) string

ButtonGroup creates a row of selectable buttons Spacing is the separator between buttons Use " " or similar for horizontal layout Use "\n" for vertical layout Defaults to " " (horizontal)

func CenterRect

func CenterRect(area uv.Rectangle, width, height int) uv.Rectangle

CenterRect returns a new [Rectangle] centered within the given area with the specified width and height.

func CopyToClipboard

func CopyToClipboard(text, successMessage string) tea.Cmd

CopyToClipboard copies the given text to the clipboard using both OSC 52 (terminal escape sequence) and native clipboard for maximum compatibility. Returns a command that reports success to the user with the given message.

func CopyToClipboardWithCallback

func CopyToClipboardWithCallback(text, successMessage string, callback tea.Cmd) tea.Cmd

CopyToClipboardWithCallback copies text to clipboard and executes a callback before showing the success message. This is useful when you need to perform additional actions like clearing UI state.

func DialogTitle

func DialogTitle(t *styles.Styles, title string, width int, fromColor, toColor color.Color) string

DialogTitle renders a dialog title without decorative diagonal lines.

func DiffFormatter

func DiffFormatter(s *styles.Styles) *diffview.DiffView

DiffFormatter returns a diff formatter with the given styles that can be used to format diff outputs.

func FormatCredits

func FormatCredits(n int) string

FormatCredits formats an integer with comma separators for thousands.

func FormatReasoningEffort

func FormatReasoningEffort(effort string) string

FormatReasoningEffort formats a reasoning effort level for display.

func InvalidateMarkdownRendererCache

func InvalidateMarkdownRendererCache()

InvalidateMarkdownRendererCache drops every cached renderer AND every per-renderer mutex in a single atomic critical section so the two maps cannot disagree mid-toggle. Call this whenever the active styles change so subsequent renderers pick up the new ansi.StyleConfig.

Existing holders of an old mutex (mid-Render goroutines) keep their reference safely; new renderers minted after the invalidation get freshly minted mutexes.

Lock ordering: mdCacheMu is acquired first, then rendererLocksMu — see the comments on each mutex.

func IsFileTooBig

func IsFileTooBig(filePath string, sizeLimit int64) (bool, error)

IsFileTooBig checks if the file at the given path exceeds the specified size limit.

func LockMarkdownRenderer

func LockMarkdownRenderer(r *glamour.TermRenderer) *sync.Mutex

LockMarkdownRenderer returns the per-renderer mutex used to serialize concurrent Render calls on a shared glamour.TermRenderer instance. The returned *sync.Mutex is stable for the lifetime of the renderer (i.e. until InvalidateMarkdownRendererCache is called).

Callers that issue more than one Render call in the same logical operation should hold the mutex for the entire sequence so other goroutines do not interleave their own Render calls and corrupt the renderer state. F8's streamingMarkdown is the immediate consumer; other call sites that today issue exactly one Render call per item render are safe without locking under the single-threaded TUI Update loop, but should adopt this lock if they ever run in parallel (e.g. background prerender workers).

func MarkdownRenderer

func MarkdownRenderer(sty *styles.Styles, width int) *glamour.TermRenderer

MarkdownRenderer returns a glamour glamour.TermRenderer configured with the given styles and width. Renderers are memoized per width and shared across callers; call InvalidateMarkdownRendererCache when the active styles change.

The returned renderer is NOT safe for concurrent Render calls (goldmark's BlockStack carries state across the public Render API). Seshat's TUI is single-threaded so production never contends, but parallel callers (most notably parallel tests) must serialize via LockMarkdownRenderer. Treat the renderer as effectively pinned to one goroutine at a time.

func ModelInfo

func ModelInfo(t *styles.Styles, modelName, providerName, reasoningInfo string, context *ModelContextInfo, width int, hyperCredits *int) string

ModelInfo renders model information including name, provider, reasoning settings, and optional context usage/cost.

func PrettyPath

func PrettyPath(t *styles.Styles, path string, width int) string

PrettyPath formats a file path with home directory shortening and applies muted styling.

func QueryCmd

func QueryCmd(env uv.Environ) tea.Cmd

QueryCmd returns a tea.Cmd that queries the terminal for different capabilities.

func QuietMarkdownRenderer

func QuietMarkdownRenderer(sty *styles.Styles, width int) *glamour.TermRenderer

QuietMarkdownRenderer returns a glamour glamour.TermRenderer with no colors (plain text with structure) and the given width. Renderers are memoized per width and shared across callers. Same concurrency contract as MarkdownRenderer: serialize via LockMarkdownRenderer.

func Scrollbar

func Scrollbar(s *styles.Styles, height, contentSize, viewportSize, offset int) string

Scrollbar renders a vertical scrollbar based on content and viewport size. Returns an empty string if content fits within viewport (no scrolling needed).

func Section

func Section(t *styles.Styles, text string, width int, info ...string) string

Section renders a section header with a title and a horizontal line filling the remaining width.

func Status

func Status(t *styles.Styles, opts StatusOpts, width int) string

Status renders a status line with icon, title, description, and extra content. The description is truncated if it exceeds the available width.

func SyntaxHighlight

func SyntaxHighlight(st *styles.Styles, source, fileName string, bg color.Color) (string, error)

SyntaxHighlight applies syntax highlighting to the given source code based on the file name and background color. It returns the highlighted code as a string.

Types

type ButtonOpts

type ButtonOpts struct {
	// Text is the button label
	Text string
	// UnderlineIndex is the 0-based index of the character to underline (-1 for none)
	UnderlineIndex int
	// Selected indicates whether this button is currently selected
	Selected bool
	// Padding inner horizontal padding defaults to 2 if this is 0
	Padding int
}

ButtonOpts defines the configuration for a single button

type Capabilities

type Capabilities struct {
	// Profile is the terminal color profile used to determine how colors are
	// rendered.
	Profile colorprofile.Profile
	// Columns is the number of character columns in the terminal.
	Columns int
	// Rows is the number of character rows in the terminal.
	Rows int
	// PixelX is the width of the terminal in pixels.
	PixelX int
	// PixelY is the height of the terminal in pixels.
	PixelY int
	// KittyGraphics indicates whether the terminal supports the Kitty graphics
	// protocol.
	KittyGraphics bool
	// SixelGraphics indicates whether the terminal supports Sixel graphics.
	SixelGraphics bool
	// Env is the terminal environment variables.
	Env uv.Environ
	// TerminalVersion is the terminal version string.
	TerminalVersion string
	// ReportFocusEvents indicates whether the terminal supports focus events.
	ReportFocusEvents bool
	// OSC99Notifications indicates whether the terminal supports OSC 99 notifications.
	OSC99Notifications bool
}

Capabilities define different terminal capabilities supported.

func (Capabilities) CellSize

func (c Capabilities) CellSize() (width, height int)

CellSize returns the size of a single terminal cell in pixels.

func (Capabilities) SupportsKittyGraphics

func (c Capabilities) SupportsKittyGraphics() bool

SupportsKittyGraphics returns true if the terminal supports Kitty graphics.

func (Capabilities) SupportsSixelGraphics

func (c Capabilities) SupportsSixelGraphics() bool

SupportsSixelGraphics returns true if the terminal supports Sixel graphics.

func (Capabilities) SupportsTrueColor

func (c Capabilities) SupportsTrueColor() bool

SupportsTrueColor returns true if the terminal supports true color.

func (*Capabilities) Update

func (c *Capabilities) Update(msg any)

Update updates the capabilities based on the given message.

type Common

type Common struct {
	Workspace workspace.Workspace
	Styles    *styles.Styles
}

Common defines common UI options and configurations.

func DefaultCommon

func DefaultCommon(ws workspace.Workspace) *Common

DefaultCommon returns the default common UI configurations. When the workspace has a large model selected, the theme is chosen based on its provider; otherwise the default theme is used.

func (*Common) Config

func (c *Common) Config() *config.Config

Config returns the pure-data configuration associated with this Common instance.

func (*Common) IsHyper

func (c *Common) IsHyper() bool

IsHyper reports whether the currently selected large model is provided by Hyper.

type Model

type Model[T any] interface {
	Update(msg tea.Msg) (T, tea.Cmd)
	View() string
}

Model represents a common interface for UI components.

type ModelContextInfo

type ModelContextInfo struct {
	ContextUsed    int64
	ModelContext   int64
	Cost           float64
	EstimatedUsage bool
}

ModelContextInfo contains token usage and cost information for a model.

type StatusOpts

type StatusOpts struct {
	Icon             string // if empty no icon will be shown
	Title            string
	TitleColor       color.Color
	Description      string
	DescriptionColor color.Color
	ExtraContent     string // additional content to append after the description
}

StatusOpts defines options for rendering a status line with icon, title, description, and optional extra content.

Jump to

Keyboard shortcuts

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