LineFold
NAME
Term::Choose::LineFold - print-columns and line-fold
DESCRIPTION
Width in this context refers to the number of occupied columns of a character string on a terminal with a monospaced font.
EXPORT
Nothing by default.
use Term::Choose::LineFold qw( print-columns );
FUNCTIONS
print-columns
Get the number of occupied columns of a character string on a terminal.
$print-width = print-columns( $string );
$print-width = print-columns( $string, %cache );
The string passed to this function is free of control characters, non-characters, and surrogates.
Passing a hash (%cache) to cache the character widths is optional.
line-fold
Fold a string.
$folded-string = line-fold( $string );
$folded-string = line-fold( $string, :120width, :1color );
Control characters (excluding vertical spaces), non-characters, and surrogates are removed before the string is folded. Changes are applied to a copy; the passed string is unchanged.
Options
width
If not set, defaults to the terminal width.
width is 1 or greater.
init-tab
Sets the initial tab inserted at the beginning of paragraphs. If a value consisting of /^<[0..9]>+$/ is provided,
the tab will be that number of spaces. Otherwise, the provided value is used directly as the tab. By default, no initial
tab is inserted. If the initial tab is longer than half the available width, it will be cut to half the available width.
subseq-tab
Sets the subsequent tab inserted at the beginning of all broken lines (excluding paragraph beginnings). If a value
consisting of /^<[0..9]>+$/ is provided, the tab will be that number of spaces. Otherwise, the provided value is
used directly as the tab. By default, no subsequent tab is inserted. If the subsequent tab is longer than half the
available width, it will be cut to half the available width.
truncate-long-tabs
If enabled (default), init-tab and subseq-tab are truncated if they exceed half of the terminal width.
color
Enables support for ANSI SGR escape sequences. If enabled, all zero-width no-break spaces (0xfeff) are removed.
color is 0 or 1.
Ambiguous width characters
By default ambiguous width characters are treated as half width. If the environment variable
TC_AMBIGUOUS_WIDTH_IS_WIDE is set to a true value, ambiguous width characters are treated as full width.
Restrictions
Term::Choose::LineFold is not installable on Windows.
AUTHOR
Matthäus Kiem <[email protected]>
LICENSE AND COPYRIGHT
Copyright (C) 2025-2026 Matthäus Kiem.
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.