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

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.

Term::Choose v2.0.6

Choose items from a list interactively.

Authors

    License

    Artistic-2.0

    Dependencies

    Term::termios

    Test Dependencies

    Provides

    • Term::Choose
    • Term::Choose::Constant
    • Term::Choose::LineFold
    • Term::Choose::LineFold::CharWidthAmbiguousWide
    • Term::Choose::LineFold::CharWidthDefault
    • Term::Choose::ReadKey
    • Term::Choose::Screen
    • Term::Choose::SetTerm

    Documentation

    The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

    Built with Podlite — the markup and publishing tools behind this site.