Help us shape the future of Go! Take the 2026 Go Developer Survey

format

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package format renders a scanned document in configurable output styles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTree

func BuildTree(paths []string) string

BuildTree renders an indented directory tree for the given relative paths.

Types

type Document

type Document struct {
	DirectoryTree string
	Files         []FileEntry
	TotalTokens   int
	// Instructions is an optional task/directive section emitted before the
	// repository body when set (--prompt).
	Instructions string
}

Document is the complete set of data handed to a Renderer.

type FileEntry

type FileEntry struct {
	Path         string
	Content      []byte
	Tokens       int
	IsCompressed bool
	Language     string

	// Picker-only fields, populated by CollectPicker for the interactive TUI.
	// SigContent is the signature-only (tree-sitter) rendering of Content.
	SigContent  []byte
	TokensFull  int
	TokensSig   int
	SecretCount int
	RankScore   float64
	Hidden      bool
	GitIgnored  bool
}

FileEntry holds one file's content and metadata for rendering.

type JSONFileEntry

type JSONFileEntry struct {
	Path    string `json:"path"`
	Content string `json:"content"` // Base64 encoded content
	Tokens  int    `json:"tokens,omitempty"`
}

JSONFileEntry is the wire format for a single file in JSON output.

type RenderOptions

type RenderOptions struct {
	UseColors bool
	Highlight highlight.Options
}

RenderOptions controls terminal-only presentation features.

type Renderer

type Renderer interface {
	Render(doc *Document, w io.Writer) error
}

Renderer renders a Document to w.

func NewRenderer

func NewRenderer(style Style, useColors bool) (Renderer, error)

NewRenderer returns a Renderer for the given style.

func NewRendererWithOptions

func NewRendererWithOptions(style Style, options RenderOptions) (Renderer, error)

NewRendererWithOptions creates a renderer with explicit terminal display options. Non-terminal renderers ignore highlighting options.

type Style

type Style string

Style identifies a supported output format.

const (
	StylePlain    Style = "plain"
	StyleMarkdown Style = "markdown"
	StyleJSON     Style = "json"
	StyleXML      Style = "xml"
)

func ParseStyle

func ParseStyle(s string) Style

ParseStyle converts a style string to a Style, defaulting to plain.

Jump to

Keyboard shortcuts

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