ui

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SymbolCheck     = "✓" // Explicit action success (created, added, etc.)
	SymbolStar      = "✦" // Concluding/summary messages (no issues, results)
	SymbolError     = "✗"
	SymbolWarning   = "!"
	SymbolInfo      = "*"
	SymbolDot       = "•"
	SymbolDash      = "—"
	SymbolAttention = "»"
)

Symbols for status indicators

View Source
const DefaultTermWidth = 120

DefaultTermWidth is the fallback terminal width when detection fails.

View Source
const MarkdownRenderMargin = 2

MarkdownRenderMargin is the left margin used for terminal markdown rendering.

Variables

View Source
var (
	// ColNum is the row number column (fixed width, right-aligned, muted).
	ColNum = ColumnDef{
		Name:     "num",
		MinWidth: 4,
		MaxWidth: 6,
		Align:    AlignRight,
		Style:    Muted,
	}

	// ColContent is the main content column (flexible width).
	ColContent = ColumnDef{
		Name:       "content",
		WidthRatio: 0.55,
		MinWidth:   30,
		MaxWidth:   100,
		Align:      AlignLeft,
	}

	// ColMeta is the metadata column (trait info, title, etc).
	ColMeta = ColumnDef{
		Name:       "meta",
		WidthRatio: 0.25,
		MinWidth:   15,
		MaxWidth:   35,
		Align:      AlignLeft,
		Style:      Muted,
	}

	// ColFile is the file location column.
	ColFile = ColumnDef{
		Name:       "file",
		WidthRatio: 0.20,
		MinWidth:   10,
		MaxWidth:   30,
		Align:      AlignLeft,
		Style:      Muted,
	}

	// ColBacklinksMeta is a wider metadata/content column used for backlinks/outlinks.
	ColBacklinksMeta = ColumnDef{
		Name:       "meta",
		WidthRatio: 0.70,
		MinWidth:   30,
		MaxWidth:   120,
		Align:      AlignLeft,
		Style:      Muted,
	}

	// ColBacklinksFile is a wider file column used for backlinks/outlinks.
	ColBacklinksFile = ColumnDef{
		Name:       "file",
		WidthRatio: 0.30,
		MinWidth:   18,
		MaxWidth:   60,
		Align:      AlignLeft,
		Style:      Muted,
	}
)

Standard column definitions shared across retrieval types.

View Source
var (
	// SearchLayout is used for search results: [num, content, meta, file]
	SearchLayout = []ColumnDef{ColNum, ColContent, ColMeta, ColFile}

	// TraitLayout is used for trait query results: [num, content, meta, file]
	TraitLayout = []ColumnDef{ColNum, ColContent, ColMeta, ColFile}

	// BacklinksLayout is used for backlinks: [num, meta, file]
	BacklinksLayout = []ColumnDef{ColNum, ColBacklinksMeta, ColBacklinksFile}
)

Standard layouts for each retrieval type.

View Source
var (
	// Muted style for secondary info, hints, line numbers
	Muted = lipgloss.NewStyle().Foreground(lipgloss.Color("8")) // Bright Black (gray)

	// Bold style for emphasis and highlights
	Bold = lipgloss.NewStyle().Bold(true)

	// Accent style for optional user-configurable highlights.
	// Defaults to Bold with no color when accent is not configured.
	Accent = Bold

	// Syntax style for code-like tokens and Raven syntax markers.
	// Defaults to cyan for visibility when no accent is configured.
	Syntax = lipgloss.NewStyle().Foreground(lipgloss.Color("6")).Bold(true)

	// SyntaxSubtle style for supporting syntax values.
	SyntaxSubtle = lipgloss.NewStyle().Foreground(lipgloss.Color("6"))
)

Functions

func AccentColor

func AccentColor() (string, bool)

AccentColor returns the currently configured accent color, if any.

func AccentDivider

func AccentDivider(label string, width int) string

AccentDivider returns a section divider rendered with the accent style.

func Badge

func Badge(text string) string

Badge returns a styled badge/pill like "[today]" or "(3)"

func Bullet

func Bullet(msg string) string

Bullet returns a bullet-prefixed item string.

func Check

func Check(msg string) string

Check returns a message with checkmark symbol (for explicit action success)

func Checkf

func Checkf(format string, args ...interface{}) string

Checkf returns a formatted message with checkmark symbol

func ConfigureMarkdownCodeTheme

func ConfigureMarkdownCodeTheme(theme string)

ConfigureMarkdownCodeTheme sets the code block theme used by Glamour. Invalid or empty values fall back to the default theme.

func ConfigureTheme

func ConfigureTheme(accent string)

ConfigureTheme configures optional UI theme colors from config. Supported accent values:

  • ANSI codes: "0" to "255"
  • Hex colors: "#RRGGBB" or "#RGB"

Special values "none", "off", and "default" disable the accent color.

func Count

func Count(n int, singular, plural string) string

Count returns a styled count badge (e.g., "(3 errors)")

func Divider

func Divider(label string, width int) string

Divider returns a section divider like "— tasks ————————————————"

func DividerWithAccentLabel

func DividerWithAccentLabel(label string, width int) string

DividerWithAccentLabel renders a divider with muted dashes and an accent label.

func Error

func Error(msg string) string

Error returns an error message with X symbol

func ErrorWarningCounts

func ErrorWarningCounts(errors, warnings int) string

ErrorWarningCounts returns a formatted count string like "(3 errors, 2 warnings)"

func Errorf

func Errorf(format string, args ...interface{}) string

Errorf returns a formatted error message with X symbol

func FieldAdd

func FieldAdd(field, value string) string

FieldAdd formats an added field as "+ field: value"

func FieldChange

func FieldChange(field, oldValue, newValue string) string

FieldChange formats a field change as "field: old → new"

func FieldRemove

func FieldRemove(field, value string) string

FieldRemove formats a removed field as "- field: value"

func FieldSet

func FieldSet(field, value string) string

FieldSet formats a new field value as "field: value"

func FilePath

func FilePath(path string) string

FilePath returns a styled file path

func FormatRowNum

func FormatRowNum(num, maxNum int) string

FormatRowNum formats a row number with consistent width.

func Header(msg string) string

Header returns a styled section header

func HighlightTraits

func HighlightTraits(text string) string

HighlightTraits highlights all @trait patterns in text. Traits are bold, values are muted. Uses parser.TraitHighlightPattern as the canonical pattern for trait matching.

func Hint

func Hint(msg string) string

Hint returns muted hint text

func Indent

func Indent(n int, text string) string

Indent returns a string indented by n spaces

func Info

func Info(msg string) string

Info returns an info message with info symbol

func Infof

func Infof(format string, args ...interface{}) string

Infof returns a formatted info message with info symbol

func LineNum

func LineNum(n int) string

LineNum returns a muted line number

func LineNumPadded

func LineNumPadded(n int, width int) string

LineNumPadded returns a muted, right-padded line number

func Metadata

func Metadata(pairs ...string) string

Metadata returns dot-separated metadata like "status: active · due: 2025-02-15"

func MetadataItem

func MetadataItem(key, value string) string

MetadataItem returns a single "key: value" metadata item

func PadRight

func PadRight(s string, width int) string

PadRight pads a string to the specified visible width, accounting for ANSI codes

func RenderMarkdown

func RenderMarkdown(content string, width int) (string, error)

RenderMarkdown renders markdown content for terminal display using the shared Raven style configuration.

func ResultCount

func ResultCount(n int) string

ResultCount returns a muted result count like "2 results"

func SectionHeader

func SectionHeader(msg string) string

SectionHeader returns a styled section header with a leading symbol.

func Star

func Star(msg string) string

Star returns a message with star symbol (for concluding/summary messages)

func Starf

func Starf(format string, args ...interface{}) string

Starf returns a formatted message with star symbol

func Trait

func Trait(traitType string, value string) string

Trait formats a trait with styling. The @ and trait name use syntax styling, and the value (if any) uses a subtle syntax style.

func TruncateWithEllipsis

func TruncateWithEllipsis(s string, maxLen int) string

TruncateWithEllipsis truncates a string to maxLen, adding ellipsis if needed. It tries to break at word boundaries.

func VisibleLen

func VisibleLen(s string) int

VisibleLen returns the visible length of a string, excluding ANSI escape codes

func Warning

func Warning(msg string) string

Warning returns a warning message with warning symbol

func Warningf

func Warningf(format string, args ...interface{}) string

Warningf returns a formatted warning message with warning symbol

func WrapTextTwoLines

func WrapTextTwoLines(text string, maxLen int) (line1, line2 string)

WrapTextTwoLines wraps text into at most two lines, with the second line truncated.

Types

type Alignment

type Alignment int

Alignment represents column text alignment.

const (
	AlignLeft Alignment = iota
	AlignRight
	AlignCenter
)

type ColumnDef

type ColumnDef struct {
	Name       string         // Header name (used for debugging, not displayed in minimal style)
	WidthRatio float64        // Proportion of available width (0.0-1.0), 0 means fixed width
	MinWidth   int            // Minimum width in characters
	MaxWidth   int            // Maximum width (0 = no limit)
	Align      Alignment      // Text alignment
	Style      lipgloss.Style // Style to apply to cells in this column
}

ColumnDef defines a column in a ResultsTable.

type DisplayContext

type DisplayContext struct {
	TermWidth int  // detected or fallback terminal width
	IsTTY     bool // whether stdout is a terminal
}

DisplayContext holds display parameters, auto-detecting terminal width. It is the single source of truth for display settings.

func NewDisplayContext

func NewDisplayContext() *DisplayContext

NewDisplayContext creates a DisplayContext, auto-detecting terminal dimensions.

func NewDisplayContextWithWidth

func NewDisplayContextWithWidth(width int) *DisplayContext

NewDisplayContextWithWidth creates a DisplayContext with a fixed width (for testing).

func (*DisplayContext) AvailableWidth

func (d *DisplayContext) AvailableWidth(leftMargin int) int

AvailableWidth returns the usable width after accounting for left margin.

type List

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

List provides a simple indented list renderer

func NewList

func NewList() *List

NewList creates a new list with default settings

func (*List) Add

func (l *List) Add(item string)

Add adds an item to the list

func (*List) SetBullet

func (l *List) SetBullet(bullet string)

SetBullet sets the bullet character

func (*List) SetIndent

func (l *List) SetIndent(indent string)

SetIndent sets the indentation string

func (*List) String

func (l *List) String() string

String renders the list as a string

type Progress

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

Progress displays a simple progress indicator for counted operations.

func NewProgress

func NewProgress(message string, total int) *Progress

NewProgress creates a new progress indicator.

func (*Progress) Done

func (p *Progress) Done()

Done finishes the progress indicator.

func (*Progress) DoneWithMessage

func (p *Progress) DoneWithMessage(message string)

DoneWithMessage finishes the progress and prints a message.

func (*Progress) Increment

func (p *Progress) Increment()

Increment increments the progress by one.

func (*Progress) Update

func (p *Progress) Update(current int)

Update updates the progress indicator.

type ResultRow

type ResultRow struct {
	Num      int      // Row number (1-indexed)
	Cells    []string // Cell values for each column
	Location string   // Location for hyperlinks (file:line format)
}

ResultRow represents a single row in the results table.

type ResultsTable

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

ResultsTable provides a unified table renderer for all retrieval types.

func NewResultsTable

func NewResultsTable(display *DisplayContext, columns []ColumnDef) *ResultsTable

NewResultsTable creates a new ResultsTable with the given display context and column layout.

func (*ResultsTable) AddRow

func (t *ResultsTable) AddRow(row ResultRow)

AddRow adds a row to the table.

func (*ResultsTable) ContentWidth

func (t *ResultsTable) ContentWidth(columnName string) int

ContentWidth returns the calculated width for a specific column by name. This allows callers to prepare content (e.g., snippet extraction) based on actual available width.

func (*ResultsTable) GetColumnWidth

func (t *ResultsTable) GetColumnWidth(index int) int

GetColumnWidth returns the calculated width for a column by index.

func (*ResultsTable) Render

func (t *ResultsTable) Render() string

Render generates the table output as a string.

type Spinner

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

Spinner displays an animated spinner with a message.

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with the given message.

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation.

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner and optionally shows a final message.

func (*Spinner) StopWithCheck

func (s *Spinner) StopWithCheck(message string)

StopWithCheck stops the spinner and prints a success message.

func (*Spinner) StopWithMessage

func (s *Spinner) StopWithMessage(message string)

StopWithMessage stops the spinner and prints a final message.

type Table

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

Table represents a simple table structure

func NewTable

func NewTable(cols int) *Table

NewTable creates a new table with the specified number of columns

func (*Table) AddRow

func (t *Table) AddRow(cells ...string)

AddRow adds a row to the table

func (*Table) SetPadding

func (t *Table) SetPadding(padding int)

SetPadding sets the padding between columns

func (*Table) String

func (t *Table) String() string

String renders the table as a string

Jump to

Keyboard shortcuts

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