textutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package textutil holds small string helpers shared across ty.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Truncate

func Truncate(s string, limit int, tail string) string

Truncate shortens s to at most limit runes, appending tail when it does.

It exists because the obvious form, s[:limit] + tail, slices BYTES. Any multi-byte character straddling the cut is split in half, leaving a dangling byte and invalid UTF-8 — which corrupts terminal layout (the renderer and the terminal disagree on the width), HTML, and any text handed to a model. Titles routinely carry a "·", an accent or an emoji, so this is not a rare case.

limit counts runes, not columns: callers here are bounding text size, not laying out a terminal. For width-sensitive rendering use ansi.Truncate, which accounts for double-width characters.

A limit at or below the length of tail returns the leading runes alone, so the result never grows past the caller's budget.

Types

This section is empty.

Jump to

Keyboard shortcuts

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