preview

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: BSD-3-Clause Imports: 13 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 LoadIndexEntry

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

LoadIndexEntry loads one cached preview by key.

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 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 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