textsafe

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 4 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 textsafe makes text from prompts, transcripts, models and settings safe to store and to print (invariant 1 in AGENTS.md). A Text can only be made here, and the render and encode code accepts nothing else, so unfiltered text cannot reach a terminal by accident.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Width

func Width(t Text) int

Width is how many terminal columns t takes.

Types

type Text

type Text struct {
	// contains filtered or unexported fields
}

Text has had its control (Cc, including C1) and format (Cf, including bidi) characters removed. The field is private, so no other package can make one from raw text; it gets one from Clean, Sane or Strip.

func Clean

func Clean(s string, max int) Text

Clean makes text for storing: one flat line, no control or format characters, no trailing spaces, at most max characters (a max below 1 means no limit). Invalid UTF-8 becomes U+FFFD, so state written by sitrep is always valid UTF-8.

func CleanMarked added in v1.0.0

func CleanMarked(s string, max int) Text

CleanMarked is Clean that ends in an ellipsis, within max characters, when it had to cut, so that a reader can tell the text is not whole.

func Fit

func Fit(t Text, cols int) Text

Fit cuts t to at most cols columns, ending in an ellipsis when it cut anything.

func Sane

func Sane(s string, max int) Text

Sane is Clean without the trailing-space trim, for the hook's own fields.

func Strip

func Strip(s string) Text

Strip makes text for showing: it removes the same characters but keeps line breaks and tabs.

func Truncate

func Truncate(t Text, max int) Text

Truncate keeps at most max characters of t (a max below 1 means no limit), with no ellipsis.

func (Text) MarshalText

func (t Text) MarshalText() ([]byte, error)

MarshalText lets a Text be a JSON string, and nothing else is accepted there.

func (Text) String

func (t Text) String() string

Jump to

Keyboard shortcuts

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