Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement for Text::ANSI::Fold module #1

Closed
kaz-utashiro opened this issue Mar 2, 2023 · 1 comment
Closed

Improvement for Text::ANSI::Fold module #1

kaz-utashiro opened this issue Mar 2, 2023 · 1 comment

Comments

@kaz-utashiro
Copy link

kaz-utashiro commented Mar 2, 2023

This is interesting.

if ($backend eq 'Text::ANSI::Fold') {
require Text::ANSI::Fold;
$para_text = join("", map {"$_\n"} Text::ANSI::Fold->new(width=>$width)->text($para_text)->chops);
$para_text =~ s/\R\z//;

As for Text::ANSI::Fold module, next program produces nicer output. When line-break mode is enabled, two extra columns are used for run-in margin. So produces maximum $width + 2 width text.

            require Text::ANSI::Fold;
            Text::ANSI::Fold->import(qw(:constants));
            state $fold = Text::ANSI::Fold->new(width => $width,
                                                boundary => 'word',
                                                linebreak => &LINEBREAK_ALL);
            $para_text = join("\n", $fold->text($para_text)->chops);
@perlancar
Copy link
Owner

Applied, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants