termtext

package
v0.54.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package termtext removes terminal control sequences from text that came from a model, a tool or another external source before chat writes it to a terminal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(value string) string

Clean removes terminal controls from one complete value.

Types

type Cleaner

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

Cleaner consumes terminal text incrementally. Escape sequences can be split across model deltas, so callers must keep one Cleaner for one displayed text stream and call Flush when that stream ends.

func (*Cleaner) Flush

func (c *Cleaner) Flush() string

Flush ends the current stream. An incomplete escape sequence or UTF-8 byte sequence is discarded; it is not safe to carry it into the next message.

func (*Cleaner) Write

func (c *Cleaner) Write(value string) string

Write removes C0/C1 controls and terminal escape sequences from value. Newline and tab are retained; every other control is removed rather than replaced so the terminal cannot interpret a visible-looking replacement as part of an escape sequence, and normal text is not made noisier by security markers.

Jump to

Keyboard shortcuts

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