codetext

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package codetext loads and normalizes user-supplied text/code for the Code typing mode. It is the I/O boundary for `--text <file>` / `--text -` so the pure-logic packages (words, typing) stay free of file/stdin access.

Normalization (full-literal-safe): strip a leading UTF-8 BOM, convert CRLF to LF, and trim exactly one trailing newline (so the snippet's final line needs no closing Enter). Tabs, interior blank lines, and indentation are preserved verbatim — Code mode requires the user to type them.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmpty    = errors.New("codetext: input is empty or whitespace-only")
	ErrBinary   = errors.New("codetext: input is not valid UTF-8 text")
	ErrTooLarge = errors.New("codetext: input exceeds the size limit")
)

Sentinel causes; callers branch with errors.Is to show a precise hint.

Functions

func Load

func Load(path string) (string, error)

Load reads from a file path, or from stdin when path == "-", then normalizes and validates. The returned string is ready to use as a Code target verbatim.

func Normalize added in v1.3.0

func Normalize(s string) (string, error)

Normalize applies the exact same BOM/binary/CRLF/trim/empty/cap pipeline as Load to an already in-memory string (no file I/O). It exists so an in-app paste is validated by identical rules/caps as `--text` — Load and Normalize share the single normalize core below, so the rules cannot diverge.

Types

This section is empty.

Jump to

Keyboard shortcuts

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