textutil

package
v0.44.48 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package textutil holds small string helpers shared across packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clip

func Clip(s string, max int) (string, bool)

Clip truncates s to at most max bytes without splitting a multibyte UTF-8 rune, returning the (possibly shorter) string and whether it was truncated. Backing off to a rune boundary avoids feeding the model — and the JSONL trace — a broken trailing rune (the byte-cap-halves-Cyrillic bug class).

func OneLine added in v0.17.0

func OneLine(s string, max int) string

OneLine collapses all runs of whitespace (incl. newlines) to single spaces and rune-safely clips the result to at most max bytes — the shared "flatten to one tidy line, capped" helper used across the packages for log/error rendering.

func Tail added in v0.23.0

func Tail(s string, max int) string

Tail keeps the last max bytes of s, backing off to a rune boundary so a multibyte character is never split; a clipped result is prefixed with "…". The counterpart of Clip for when the END of the text is the valuable part (e.g. a CLI agent's final answer after pages of progress noise).

Types

type BoundedTailWriter added in v0.41.7

type BoundedTailWriter struct {
	Truncated bool
	// contains filtered or unexported fields
}

BoundedTailWriter is an io.Writer that keeps only the most recent max bytes written to it — the tail counterpart of BoundedWriter — without ever holding more than a small bounded multiple of max bytes at once, so tailing a runaway command's output doesn't require buffering all of it first. Truncated reports whether any bytes were ever dropped.

func NewBoundedTailWriter added in v0.41.7

func NewBoundedTailWriter(max int) *BoundedTailWriter

NewBoundedTailWriter returns a BoundedTailWriter that retains at most the last max bytes written.

func (*BoundedTailWriter) String added in v0.41.7

func (w *BoundedTailWriter) String() string

String returns the retained tail, backed off to a UTF-8 rune boundary at the start since a dropped prefix can land mid-rune.

func (*BoundedTailWriter) Write added in v0.41.7

func (w *BoundedTailWriter) Write(p []byte) (int, error)

type BoundedWriter added in v0.41.7

type BoundedWriter struct {
	Truncated bool
	// contains filtered or unexported fields
}

BoundedWriter is an io.Writer that keeps only the first max bytes ever written to it, discarding the rest instead of buffering it — so wiring a subprocess's stdout/stderr to one caps this process's memory use at max regardless of how much output a runaway command produces. Truncated reports whether any bytes were dropped. Write always reports success (returns len(p), nil) since dropping the tail is by design, not an error.

func NewBoundedWriter added in v0.41.7

func NewBoundedWriter(max int) *BoundedWriter

NewBoundedWriter returns a BoundedWriter that retains at most max bytes.

func (*BoundedWriter) String added in v0.41.7

func (w *BoundedWriter) String() string

String returns the retained bytes.

func (*BoundedWriter) Write added in v0.41.7

func (w *BoundedWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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