Term::...neFold(3pm)
π Term::Choose::LineFold β the manual, but make it make sense π
okay bestie, sit down, hydrate, because this is Term::Choose::LineFold, a lil Perl module from the User Contributed Perl Documentation section of the manual. she's a Perl module (that's the 3pm energy, iykyk) and she's here to help you figure out how much space your strings are eating on a terminal. let's get into it π
β¨ VERSION β¨
Version 1.782 β that's the one, that's what we're working with π
πΈ DESCRIPTION πΈ
okay so first things first, we're talking about width, and in this context width means the number of occupied columns of a character string on a terminal that has a monospaced font. one character, one column-ish, basically. periodt.
by default, ambiguous width characters are treated as half width. but β plot twist β if the environment variable TC_AMBIGUOUS_WIDTH_IS_WIDE is set to a true value, then ambiguous width characters get treated as full width. no cap, that's the whole switch.
and now the glow-up news: if the optional Term::Choose::LineFold::XS module happens to be installed, its functions will be used automatically in place of the pure-Perl implementations, which gives you faster performance. she upgraded herself, we love that for her β¨
π EXPORT π
Nothing by default. like, literally nothing, she's shy at first.
but if you want something, you ask for it:
use Term::Choose::LineFold qw( print_columns );
and then she's yours π«Ά
π FUNCTIONS π
π print_columns
Get the number of occupied columns of a character string on a terminal. that's it, that's the gig.
the string you pass in must be a decoded string, and it has to be free of control characters, non-characters, and surrogates. don't send her your messy unprocessed trauma strings, she will not fold them.
$print_width = print_columns( $string );
π line_fold
Fold a string. like folding a fitted sheet but for text, and actually possible.
this function accepts a decoded string. here's the part where she does some light housekeeping: control characters (excluding vertical spaces), non-characters, and surrogates are removed before the string gets folded. also super important β changes are applied to a copy; the passed string is unchanged. your original stays pristine, no side effects, main character energy only for the copy π
$folded_string = line_fold( $string );
$folded_string = line_fold( $string, { width => 120, color => 1 } );
β¨ Options β¨
widthβ if you don't set it, it defaults to the terminal width. and heads up,widthis1or greater. no zero, no negatives, we don't do that here.init_tabβ sets the initial tab inserted at the beginning of paragraphs. if you give her a value that consists of the pattern/^[0-9]+$/, the tab becomes that number of spaces. otherwise, whatever value you provided is used directly as the tab. by default, no initial tab is inserted. and one lil caveat: if the initial tab ends up longer than half the available width, it gets cut down to half the available width. she trims, she's polite about it πsubseq_tabβ sets the subsequent tab inserted at the beginning of all broken lines (excluding paragraph beginnings). same deal as above: a/^[0-9]+$/value means that many spaces, anything else is used directly as the tab. by default, no subsequent tab is inserted. and yep, same rule β if the subsequent tab is longer than half the available width, it gets cut to half the available width.truncate_long_tabsβ if enabled (and it is enabled by default),init_tabandsubseq_tabare truncated if they exceed half of the terminal width. this is the switch that does the trimming described above. iconic behavior, honestly.colorβ enables support for ANSI SGR escape sequences. if enabled, all zero-width no-break spaces (0xfeff) are removed. andcoloris0or1β binary, no in-between, no "kind of", pick a lane bestie.
π AUTHOR π
MatthΓ€us Kiem <cuer2s@gmail.com> β give them their flowers π
π 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 same terms as Perl 5.10.0. for the full deets, go read the licenses in the file LICENSE. no vibes-based licensing here, read the actual text, fr fr π«Ά
aaaand that's the whole page, bestie π¦ this was Term::Choose::LineFold, perl v5.40.1, dated 2026-05-06 β go forth and fold your lines, you've got this πβ¨π
π¦ where this page comes from
- ubuntu stonking: libterm-choose-perl 1.782-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms