preview

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MaxIndexBytes = 8 << 20

MaxIndexBytes is the byte budget for preview index storage.

Variables

This section is empty.

Functions

func BuildLines

func BuildLines(path string, width, lines int, palette ThemePalette) []string

BuildLines renders preview entries from one session file.

func CacheKeyForSession

func CacheKeyForSession(path string, width int, sizeBytes int64, updatedAtUnix int64) string

CacheKeyForSession derives a stable preview cache key from session metadata.

func LinesBytes

func LinesBytes(lines []string) int64

LinesBytes returns raw string bytes occupied by preview lines.

func LoadCmd added in v0.3.2

func LoadCmd(req Request) tea.Cmd

func LoadIndexEntry

func LoadIndexEntry(path, key string) ([]string, bool, error)

LoadIndexEntry loads one cached preview by key.

func PersistIndexCmd added in v0.3.2

func PersistIndexCmd(indexPath string, cap int, record IndexRecord) tea.Cmd

func ReadIndex

func ReadIndex(path string) (map[string]IndexRecord, bool, error)

ReadIndex reads all records. Corrupted lines are skipped and flagged.

func RecordBytes

func RecordBytes(rec IndexRecord) int64

RecordBytes estimates one index record byte footprint.

func RewriteIndex

func RewriteIndex(path string, entries map[string]IndexRecord, cap int, maxBytes int64) error

RewriteIndex rewrites index with cap and byte-limit trimming.

func TrimIndexBytes

func TrimIndexBytes(entries map[string]IndexRecord, totalBytes, maxBytes int64) int64

TrimIndexBytes evicts oldest records until byte budget is satisfied.

func UpsertIndex

func UpsertIndex(path string, cap int, record IndexRecord) error

UpsertIndex inserts or updates one preview index record.

func WithIndexLock

func WithIndexLock(lockPath string, timeout time.Duration, fn func() error) error

WithIndexLock runs fn under an index lock file with timeout.

Types

type AngleTagTone added in v0.3.2

type AngleTagTone int

AngleTagTone classifies angle-bracket tag semantics for highlight styling.

const (
	AngleTagToneDefault AngleTagTone = iota
	AngleTagToneSystem
	AngleTagToneLifecycle
	AngleTagToneDanger
	AngleTagToneSuccess
)

func ClassifyAngleTag added in v0.3.2

func ClassifyAngleTag(tag string) AngleTagTone

ClassifyAngleTag applies semantic tag classification for preview coloring.

type HandleLoadedOutput added in v0.3.2

type HandleLoadedOutput struct {
	Accepted   bool
	NextWait   string
	CacheKey   string
	CacheLines []string
	PersistCmd tea.Cmd
}

func HandleLoaded added in v0.3.2

func HandleLoaded(currentReqID uint64, waitKey string, msg LoadedMsg, indexPath string, cap int) HandleLoadedOutput

HandleLoaded validates stale async messages and returns cache/persist actions.

type IndexPersistedMsg added in v0.3.2

type IndexPersistedMsg struct {
	Err string
}

IndexPersistedMsg is emitted after index persistence.

type IndexRecord

type IndexRecord struct {
	Key           string   `json:"key"`
	Path          string   `json:"path"`
	Width         int      `json:"width"`
	SizeBytes     int64    `json:"size_bytes"`
	UpdatedAtUnix int64    `json:"updated_at_unix"`
	TouchedAtUnix int64    `json:"touched_at_unix"`
	Lines         []string `json:"lines"`
}

IndexRecord is one preview index row.

type LoadedMsg added in v0.3.2

type LoadedMsg struct {
	RequestID uint64
	Key       string
	Lines     []string
	Err       string
	Record    IndexRecord
}

LoadedMsg is emitted after a preview load.

type Request added in v0.3.2

type Request struct {
	RequestID     uint64
	Key           string
	Path          string
	Width         int
	Lines         int
	Palette       ThemePalette
	IndexPath     string
	SizeBytes     int64
	UpdatedAtUnix int64
}

Request describes one async preview load.

type ThemePalette

type ThemePalette struct {
	PrefixDefault   string
	PrefixUser      string
	PrefixAssistant string
	PrefixOther     string
	TagDanger       string
	TagDefault      string
	TagSystem       string
	TagLifecycle    string
	TagSuccess      string
}

ThemePalette stores semantic preview colors already resolved by the caller.

Jump to

Keyboard shortcuts

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