wordwrap

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package wordwrap provides terminal-aware word wrapping for streaming text output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TerminalWidth

func TerminalWidth(fallback int) int

TerminalWidth returns the current terminal width, or fallback if unavailable.

func Wrap

func Wrap(text string, width int) string

Wrap wraps text to the given width at word boundaries. It preserves existing newlines and handles multi-line input.

Types

type StreamWriter

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

StreamWriter wraps streaming text output at the given column width. It buffers partial words and flushes complete wrapped lines.

func NewStreamWriter

func NewStreamWriter(width int, output func(string)) *StreamWriter

NewStreamWriter creates a streaming word wrapper. width=0 means no wrapping (passthrough).

func (*StreamWriter) Flush

func (w *StreamWriter) Flush()

Flush outputs any remaining buffered content.

func (*StreamWriter) Write

func (w *StreamWriter) Write(token string)

Write processes a token from the LLM stream.

Jump to

Keyboard shortcuts

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