truncate

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxLines = 2000
	DefaultMaxBytes = 50 * 1024 // 50KB
)
View Source
const (
	MaxFetchBody    = 10 << 20 // 10MB
	MaxResponseBody = 1 << 20  // 1MB
)
View Source
const (
	GrepMaxLineLength = 500
	MaxGlobResults    = 500
	MaxImageSize      = 20 << 20 // 20MB
)
View Source
const MaxContentLength = 100_000

Variables

This section is empty.

Functions

func Clip

func Clip(s string, maxLen int) string

Clip collapses whitespace (newlines → spaces, multiple spaces → one), then truncates to maxLen bytes at a UTF-8 boundary, appending "...".

func ClipLines

func ClipLines(text string, maxLines, maxWidth int) ([]string, int)

ClipLines keeps at most maxLines lines, each truncated to maxWidth runes. Returns the selected lines and the count of hidden lines.

func ClipRunes

func ClipRunes(s string, maxRunes int) string

ClipRunes truncates by rune count, appending "…" (unicode ellipsis).

func FormatSize

func FormatSize(bytes int) string

FormatSize returns a human-readable size string.

func Line

func Line(line string, maxChars int) (string, bool)

Line truncates a single line to maxChars runes, appending "... [truncated]".

Types

type Options

type Options struct {
	MaxLines int
	MaxBytes int
}

type Result

type Result struct {
	Content               string
	Truncated             bool
	TruncatedBy           Strategy
	TotalLines            int
	TotalBytes            int
	OutputLines           int
	OutputBytes           int
	FirstLineExceedsLimit bool
	MaxLines              int
	MaxBytes              int
}
func Head(content string, opts Options) Result

Head keeps the first N lines / N bytes. Never returns partial lines. If the first line alone exceeds MaxBytes, returns empty content with FirstLineExceedsLimit=true.

func Tail

func Tail(content string, opts Options) Result

Tail keeps the last N lines / N bytes. May return a partial first line when the last line alone exceeds MaxBytes.

type Strategy

type Strategy string
const (
	ByLines Strategy = "lines"
	ByBytes Strategy = "bytes"
	None    Strategy = ""
)

Jump to

Keyboard shortcuts

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