Text-ANSI-Util-0.233/0000775000175000017500000000000014104005531011537 5ustar u1u1Text-ANSI-Util-0.233/Makefile.PL0000644000175000017500000000265414104005531013516 0ustar u1u1# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.017. use strict; use warnings; use 5.010001; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Routines for text containing ANSI color codes", "AUTHOR" => "perlancar ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Text-ANSI-Util", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.010001", "NAME" => "Text::ANSI::Util", "PREREQ_PM" => { "Exporter" => "5.57", "List::Util" => "1.45", "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Data::Dump" => 0, "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "POSIX" => 0, "Test::More" => "0.98", "constant" => 0 }, "VERSION" => "0.233", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Data::Dump" => 0, "Exporter" => "5.57", "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "List::Util" => "1.45", "POSIX" => 0, "Test::More" => "0.98", "constant" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Text-ANSI-Util-0.233/META.yml0000644000175000017500000003446414104005531013021 0ustar u1u1--- abstract: 'Routines for text containing ANSI color codes' author: - 'perlancar ' build_requires: Data::Dump: '0' File::Spec: '0' IO::Handle: '0' IPC::Open3: '0' POSIX: '0' Test::More: '0.98' constant: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Text-ANSI-Util requires: Exporter: '5.57' List::Util: '1.45' perl: '5.010001' strict: '0' warnings: '0' resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Text-ANSI-Util homepage: https://metacpan.org/release/Text-ANSI-Util repository: git://github.com/perlancar/perl-Text-ANSI-Util.git version: '0.233' x_Dist_Zilla: perl: version: '5.034000' plugins: - class: Dist::Zilla::Plugin::InsertBlock name: InsertBlock version: '0.100' - class: Dist::Zilla::Plugin::PERLANCAR::CheckPendingRelease name: '@Author::PERLANCAR/PERLANCAR::CheckPendingRelease' version: '0.001' - class: Dist::Zilla::Plugin::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: [] exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . name: '@Author::PERLANCAR/@Filter/GatherDir' version: '6.017' - class: Dist::Zilla::Plugin::PruneCruft name: '@Author::PERLANCAR/@Filter/PruneCruft' version: '6.017' - class: Dist::Zilla::Plugin::ManifestSkip name: '@Author::PERLANCAR/@Filter/ManifestSkip' version: '6.017' - class: Dist::Zilla::Plugin::MetaYAML name: '@Author::PERLANCAR/@Filter/MetaYAML' version: '6.017' - class: Dist::Zilla::Plugin::License name: '@Author::PERLANCAR/@Filter/License' version: '6.017' - class: Dist::Zilla::Plugin::PodCoverageTests name: '@Author::PERLANCAR/@Filter/PodCoverageTests' version: '6.017' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@Author::PERLANCAR/@Filter/PodSyntaxTests' version: '6.017' - class: Dist::Zilla::Plugin::ExtraTests name: '@Author::PERLANCAR/@Filter/ExtraTests' version: '6.017' - class: Dist::Zilla::Plugin::ExecDir name: '@Author::PERLANCAR/@Filter/ExecDir' version: '6.017' - class: Dist::Zilla::Plugin::ShareDir name: '@Author::PERLANCAR/@Filter/ShareDir' version: '6.017' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Author::PERLANCAR/@Filter/MakeMaker' version: '6.017' - class: Dist::Zilla::Plugin::Manifest name: '@Author::PERLANCAR/@Filter/Manifest' version: '6.017' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Author::PERLANCAR/@Filter/ConfirmRelease' version: '6.017' - class: Dist::Zilla::Plugin::ExecDir name: '@Author::PERLANCAR/ExecDir script' version: '6.017' - class: Dist::Zilla::Plugin::PERLANCAR::BeforeBuild name: '@Author::PERLANCAR/PERLANCAR::BeforeBuild' version: '0.604' - class: Dist::Zilla::Plugin::Rinci::AbstractFromMeta name: '@Author::PERLANCAR/Rinci::AbstractFromMeta' version: '0.10' - class: Dist::Zilla::Plugin::PodnameFromFilename name: '@Author::PERLANCAR/PodnameFromFilename' version: '0.02' - class: Dist::Zilla::Plugin::PERLANCAR::EnsurePrereqToSpec name: '@Author::PERLANCAR/PERLANCAR::EnsurePrereqToSpec' version: '0.062' - class: Dist::Zilla::Plugin::PERLANCAR::MetaResources name: '@Author::PERLANCAR/PERLANCAR::MetaResources' version: '0.043' - class: Dist::Zilla::Plugin::CheckChangeLog name: '@Author::PERLANCAR/CheckChangeLog' version: '0.05' - class: Dist::Zilla::Plugin::CheckMetaResources name: '@Author::PERLANCAR/CheckMetaResources' version: '0.001' - class: Dist::Zilla::Plugin::CheckSelfDependency config: Dist::Zilla::Plugin::CheckSelfDependency: finder: - ':InstallModules' Dist::Zilla::Role::ModuleMetadata: Module::Metadata: '1.000037' version: '0.006' name: '@Author::PERLANCAR/CheckSelfDependency' version: '0.011' - class: Dist::Zilla::Plugin::Git::Contributors config: Dist::Zilla::Plugin::Git::Contributors: git_version: 2.25.1 include_authors: 0 include_releaser: 1 order_by: name paths: [] name: '@Author::PERLANCAR/Git::Contributors' version: '0.036' - class: Dist::Zilla::Plugin::CopyrightYearFromGit name: '@Author::PERLANCAR/CopyrightYearFromGit' version: '0.006' - class: Dist::Zilla::Plugin::IfBuilt name: '@Author::PERLANCAR/IfBuilt' version: '0.02' - class: Dist::Zilla::Plugin::MetaJSON name: '@Author::PERLANCAR/MetaJSON' version: '6.017' - class: Dist::Zilla::Plugin::MetaConfig name: '@Author::PERLANCAR/MetaConfig' version: '6.017' - class: Dist::Zilla::Plugin::PERLANCAR::Authority name: '@Author::PERLANCAR/PERLANCAR::Authority' version: '0.001' - class: Dist::Zilla::Plugin::OurDate name: '@Author::PERLANCAR/OurDate' version: '0.03' - class: Dist::Zilla::Plugin::OurDist name: '@Author::PERLANCAR/OurDist' version: '0.02' - class: Dist::Zilla::Plugin::OurPkgVersion name: '@Author::PERLANCAR/OurPkgVersion' version: '0.21' - class: Dist::Zilla::Plugin::PodWeaver config: Dist::Zilla::Plugin::PodWeaver: finder: - ':InstallModules' - ':ExecFiles' plugins: - class: Pod::Weaver::Plugin::EnsurePod5 name: '@CorePrep/EnsurePod5' version: '4.017' - class: Pod::Weaver::Plugin::H1Nester name: '@CorePrep/H1Nester' version: '4.017' - class: Pod::Weaver::Section::Name name: '@Author::PERLANCAR/Name' version: '4.017' - class: Pod::Weaver::Section::Version name: '@Author::PERLANCAR/Version' version: '4.017' - class: Pod::Weaver::Section::Region name: '@Author::PERLANCAR/prelude' version: '4.017' - class: Pod::Weaver::Section::Generic name: SYNOPSIS version: '4.017' - class: Pod::Weaver::Section::Generic name: DESCRIPTION version: '4.017' - class: Pod::Weaver::Section::Generic name: OVERVIEW version: '4.017' - class: Pod::Weaver::Section::Collect name: ATTRIBUTES version: '4.017' - class: Pod::Weaver::Section::Collect name: METHODS version: '4.017' - class: Pod::Weaver::Section::Collect name: FUNCTIONS version: '4.017' - class: Pod::Weaver::Section::Leftovers name: '@Author::PERLANCAR/Leftovers' version: '4.017' - class: Pod::Weaver::Section::Region name: '@Author::PERLANCAR/postlude' version: '4.017' - class: Pod::Weaver::Section::Completion::GetoptLongComplete name: '@Author::PERLANCAR/Completion::GetoptLongComplete' version: '0.08' - class: Pod::Weaver::Section::Completion::GetoptLongSubcommand name: '@Author::PERLANCAR/Completion::GetoptLongSubcommand' version: '0.04' - class: Pod::Weaver::Section::Completion::GetoptLongMore name: '@Author::PERLANCAR/Completion::GetoptLongMore' version: '0.001' - class: Pod::Weaver::Section::Homepage::DefaultCPAN name: '@Author::PERLANCAR/Homepage::DefaultCPAN' version: '0.05' - class: Pod::Weaver::Section::Source::DefaultGitHub name: '@Author::PERLANCAR/Source::DefaultGitHub' version: '0.07' - class: Pod::Weaver::Section::Bugs::DefaultRT name: '@Author::PERLANCAR/Bugs::DefaultRT' version: '0.06' - class: Pod::Weaver::Section::Authors name: '@Author::PERLANCAR/Authors' version: '4.017' - class: Pod::Weaver::Section::Contributors name: '@Author::PERLANCAR/Contributors' version: '0.009' - class: Pod::Weaver::Section::Legal name: '@Author::PERLANCAR/Legal' version: '4.017' - class: Pod::Weaver::Plugin::Rinci name: '@Author::PERLANCAR/Rinci' version: '0.780' - class: Pod::Weaver::Plugin::AppendPrepend name: '@Author::PERLANCAR/AppendPrepend' version: '0.01' - class: Pod::Weaver::Plugin::EnsureUniqueSections name: '@Author::PERLANCAR/EnsureUniqueSections' version: '0.163250' - class: Pod::Weaver::Plugin::SingleEncoding name: '@Author::PERLANCAR/SingleEncoding' version: '4.017' - class: Pod::Weaver::Plugin::PERLANCAR::SortSections name: '@Author::PERLANCAR/PERLANCAR::SortSections' version: '0.082' name: '@Author::PERLANCAR/PodWeaver' version: '4.008' - class: Dist::Zilla::Plugin::PruneFiles name: '@Author::PERLANCAR/PruneFiles' version: '6.017' - class: Dist::Zilla::Plugin::Pod2Readme name: '@Author::PERLANCAR/Pod2Readme' version: '0.004' - class: Dist::Zilla::Plugin::Rinci::AddPrereqs name: '@Author::PERLANCAR/Rinci::AddPrereqs' version: '0.145' - class: Dist::Zilla::Plugin::Rinci::AddToDb name: '@Author::PERLANCAR/Rinci::AddToDb' version: '0.020' - class: Dist::Zilla::Plugin::Rinci::EmbedValidator name: '@Author::PERLANCAR/Rinci::EmbedValidator' version: '0.251' - class: Dist::Zilla::Plugin::SetScriptShebang name: '@Author::PERLANCAR/SetScriptShebang' version: '0.01' - class: Dist::Zilla::Plugin::Test::Compile config: Dist::Zilla::Plugin::Test::Compile: bail_out_on_fail: '0' fail_on_warning: author fake_home: 0 filename: t/00-compile.t module_finder: - ':InstallModules' needs_display: 0 phase: test script_finder: - ':PerlExecFiles' skips: [] switch: [] name: '@Author::PERLANCAR/Test::Compile' version: '2.058' - class: Dist::Zilla::Plugin::Test::Perl::Critic::Subset config: Dist::Zilla::Plugin::Test::Perl::Critic::Subset: finder: - ':ExecFiles' - ':InstallModules' - ':TestFiles' name: '@Author::PERLANCAR/Test::Perl::Critic::Subset' version: 3.001.005 - class: Dist::Zilla::Plugin::Test::Rinci name: '@Author::PERLANCAR/Test::Rinci' version: '0.040' - class: Dist::Zilla::Plugin::StaticInstall config: Dist::Zilla::Plugin::StaticInstall: dry_run: 0 mode: on name: '@Author::PERLANCAR/StaticInstall' version: '0.012' - class: Dist::Zilla::Plugin::EnsureSQLSchemaVersionedTest name: '@Author::PERLANCAR/EnsureSQLSchemaVersionedTest' version: '0.03' - class: Dist::Zilla::Plugin::Acme::CPANModules::Blacklist name: '@Author::PERLANCAR/Acme::CPANModules::Blacklist' version: '0.001' - class: Dist::Zilla::Plugin::Prereqs::EnsureVersion name: '@Author::PERLANCAR/Prereqs::EnsureVersion' version: '0.050' - class: Dist::Zilla::Plugin::Prereqs::CheckCircular name: '@Author::PERLANCAR/Prereqs::CheckCircular' version: '0.006' - class: Dist::Zilla::Plugin::UploadToCPAN::WWWPAUSESimple name: '@Author::PERLANCAR/UploadToCPAN::WWWPAUSESimple' version: '0.04' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: TestRequires version: '6.017' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: runtime type: requires name: Prereqs version: '6.017' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.017' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.017' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.017' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.017' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.017' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.017' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.017' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.017' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.017' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.017' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '6.017' x_authority: cpan:PERLANCAR x_contributors: - 'Steven Haryanto (on PC) ' x_generated_by_perl: v5.34.0 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' x_static_install: 1 Text-ANSI-Util-0.233/weaver.ini0000644000175000017500000000002514104005531013524 0ustar u1u1[@Author::PERLANCAR] Text-ANSI-Util-0.233/dist.ini0000644000175000017500000000063714104005531013207 0ustar u1u1;--------------------------------- author = perlancar copyright_holder = perlancar license = Perl_5 ;--------------------------------- version=0.233 name=Text-ANSI-Util [InsertBlock] [@Author::PERLANCAR] :version=0.604 [Prereqs / TestRequires] constant=0 Data::Dump=0 POSIX=0 Test::More=0.98 [Prereqs] perl=5.010001 strict=0 warnings=0 Exporter=5.57 List::Util=1.45 Text-ANSI-Util-0.233/META.json0000644000175000017500000005263514104005531013171 0ustar u1u1{ "abstract" : "Routines for text containing ANSI color codes", "author" : [ "perlancar " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Text-ANSI-Util", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Perl::Critic" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Exporter" : "5.57", "List::Util" : "1.45", "perl" : "5.010001", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Data::Dump" : "0", "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "POSIX" : "0", "Test::More" : "0.98", "constant" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Text-ANSI-Util" }, "homepage" : "https://metacpan.org/release/Text-ANSI-Util", "repository" : { "type" : "git", "url" : "git://github.com/perlancar/perl-Text-ANSI-Util.git", "web" : "https://github.com/perlancar/perl-Text-ANSI-Util" } }, "version" : "0.233", "x_Dist_Zilla" : { "perl" : { "version" : "5.034000" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::InsertBlock", "name" : "InsertBlock", "version" : "0.100" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::CheckPendingRelease", "name" : "@Author::PERLANCAR/PERLANCAR::CheckPendingRelease", "version" : "0.001" }, { "class" : "Dist::Zilla::Plugin::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." } }, "name" : "@Author::PERLANCAR/@Filter/GatherDir", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Author::PERLANCAR/@Filter/PruneCruft", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Author::PERLANCAR/@Filter/ManifestSkip", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Author::PERLANCAR/@Filter/MetaYAML", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Author::PERLANCAR/@Filter/License", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::PodCoverageTests", "name" : "@Author::PERLANCAR/@Filter/PodCoverageTests", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@Author::PERLANCAR/@Filter/PodSyntaxTests", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@Author::PERLANCAR/@Filter/ExtraTests", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::PERLANCAR/@Filter/ExecDir", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Author::PERLANCAR/@Filter/ShareDir", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Author::PERLANCAR/@Filter/MakeMaker", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Author::PERLANCAR/@Filter/Manifest", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Author::PERLANCAR/@Filter/ConfirmRelease", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::PERLANCAR/ExecDir script", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::BeforeBuild", "name" : "@Author::PERLANCAR/PERLANCAR::BeforeBuild", "version" : "0.604" }, { "class" : "Dist::Zilla::Plugin::Rinci::AbstractFromMeta", "name" : "@Author::PERLANCAR/Rinci::AbstractFromMeta", "version" : "0.10" }, { "class" : "Dist::Zilla::Plugin::PodnameFromFilename", "name" : "@Author::PERLANCAR/PodnameFromFilename", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::EnsurePrereqToSpec", "name" : "@Author::PERLANCAR/PERLANCAR::EnsurePrereqToSpec", "version" : "0.062" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::MetaResources", "name" : "@Author::PERLANCAR/PERLANCAR::MetaResources", "version" : "0.043" }, { "class" : "Dist::Zilla::Plugin::CheckChangeLog", "name" : "@Author::PERLANCAR/CheckChangeLog", "version" : "0.05" }, { "class" : "Dist::Zilla::Plugin::CheckMetaResources", "name" : "@Author::PERLANCAR/CheckMetaResources", "version" : "0.001" }, { "class" : "Dist::Zilla::Plugin::CheckSelfDependency", "config" : { "Dist::Zilla::Plugin::CheckSelfDependency" : { "finder" : [ ":InstallModules" ] }, "Dist::Zilla::Role::ModuleMetadata" : { "Module::Metadata" : "1.000037", "version" : "0.006" } }, "name" : "@Author::PERLANCAR/CheckSelfDependency", "version" : "0.011" }, { "class" : "Dist::Zilla::Plugin::Git::Contributors", "config" : { "Dist::Zilla::Plugin::Git::Contributors" : { "git_version" : "2.25.1", "include_authors" : 0, "include_releaser" : 1, "order_by" : "name", "paths" : [] } }, "name" : "@Author::PERLANCAR/Git::Contributors", "version" : "0.036" }, { "class" : "Dist::Zilla::Plugin::CopyrightYearFromGit", "name" : "@Author::PERLANCAR/CopyrightYearFromGit", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::IfBuilt", "name" : "@Author::PERLANCAR/IfBuilt", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@Author::PERLANCAR/MetaJSON", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@Author::PERLANCAR/MetaConfig", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::Authority", "name" : "@Author::PERLANCAR/PERLANCAR::Authority", "version" : "0.001" }, { "class" : "Dist::Zilla::Plugin::OurDate", "name" : "@Author::PERLANCAR/OurDate", "version" : "0.03" }, { "class" : "Dist::Zilla::Plugin::OurDist", "name" : "@Author::PERLANCAR/OurDist", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::OurPkgVersion", "name" : "@Author::PERLANCAR/OurPkgVersion", "version" : "0.21" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "finder" : [ ":InstallModules", ":ExecFiles" ], "plugins" : [ { "class" : "Pod::Weaver::Plugin::EnsurePod5", "name" : "@CorePrep/EnsurePod5", "version" : "4.017" }, { "class" : "Pod::Weaver::Plugin::H1Nester", "name" : "@CorePrep/H1Nester", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Name", "name" : "@Author::PERLANCAR/Name", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Version", "name" : "@Author::PERLANCAR/Version", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@Author::PERLANCAR/prelude", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "SYNOPSIS", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "DESCRIPTION", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "OVERVIEW", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "ATTRIBUTES", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "METHODS", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "FUNCTIONS", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Leftovers", "name" : "@Author::PERLANCAR/Leftovers", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@Author::PERLANCAR/postlude", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Completion::GetoptLongComplete", "name" : "@Author::PERLANCAR/Completion::GetoptLongComplete", "version" : "0.08" }, { "class" : "Pod::Weaver::Section::Completion::GetoptLongSubcommand", "name" : "@Author::PERLANCAR/Completion::GetoptLongSubcommand", "version" : "0.04" }, { "class" : "Pod::Weaver::Section::Completion::GetoptLongMore", "name" : "@Author::PERLANCAR/Completion::GetoptLongMore", "version" : "0.001" }, { "class" : "Pod::Weaver::Section::Homepage::DefaultCPAN", "name" : "@Author::PERLANCAR/Homepage::DefaultCPAN", "version" : "0.05" }, { "class" : "Pod::Weaver::Section::Source::DefaultGitHub", "name" : "@Author::PERLANCAR/Source::DefaultGitHub", "version" : "0.07" }, { "class" : "Pod::Weaver::Section::Bugs::DefaultRT", "name" : "@Author::PERLANCAR/Bugs::DefaultRT", "version" : "0.06" }, { "class" : "Pod::Weaver::Section::Authors", "name" : "@Author::PERLANCAR/Authors", "version" : "4.017" }, { "class" : "Pod::Weaver::Section::Contributors", "name" : "@Author::PERLANCAR/Contributors", "version" : "0.009" }, { "class" : "Pod::Weaver::Section::Legal", "name" : "@Author::PERLANCAR/Legal", "version" : "4.017" }, { "class" : "Pod::Weaver::Plugin::Rinci", "name" : "@Author::PERLANCAR/Rinci", "version" : "0.780" }, { "class" : "Pod::Weaver::Plugin::AppendPrepend", "name" : "@Author::PERLANCAR/AppendPrepend", "version" : "0.01" }, { "class" : "Pod::Weaver::Plugin::EnsureUniqueSections", "name" : "@Author::PERLANCAR/EnsureUniqueSections", "version" : "0.163250" }, { "class" : "Pod::Weaver::Plugin::SingleEncoding", "name" : "@Author::PERLANCAR/SingleEncoding", "version" : "4.017" }, { "class" : "Pod::Weaver::Plugin::PERLANCAR::SortSections", "name" : "@Author::PERLANCAR/PERLANCAR::SortSections", "version" : "0.082" } ] } }, "name" : "@Author::PERLANCAR/PodWeaver", "version" : "4.008" }, { "class" : "Dist::Zilla::Plugin::PruneFiles", "name" : "@Author::PERLANCAR/PruneFiles", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::Pod2Readme", "name" : "@Author::PERLANCAR/Pod2Readme", "version" : "0.004" }, { "class" : "Dist::Zilla::Plugin::Rinci::AddPrereqs", "name" : "@Author::PERLANCAR/Rinci::AddPrereqs", "version" : "0.145" }, { "class" : "Dist::Zilla::Plugin::Rinci::AddToDb", "name" : "@Author::PERLANCAR/Rinci::AddToDb", "version" : "0.020" }, { "class" : "Dist::Zilla::Plugin::Rinci::EmbedValidator", "name" : "@Author::PERLANCAR/Rinci::EmbedValidator", "version" : "0.251" }, { "class" : "Dist::Zilla::Plugin::SetScriptShebang", "name" : "@Author::PERLANCAR/SetScriptShebang", "version" : "0.01" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "config" : { "Dist::Zilla::Plugin::Test::Compile" : { "bail_out_on_fail" : 0, "fail_on_warning" : "author", "fake_home" : 0, "filename" : "t/00-compile.t", "module_finder" : [ ":InstallModules" ], "needs_display" : 0, "phase" : "test", "script_finder" : [ ":PerlExecFiles" ], "skips" : [], "switch" : [] } }, "name" : "@Author::PERLANCAR/Test::Compile", "version" : "2.058" }, { "class" : "Dist::Zilla::Plugin::Test::Perl::Critic::Subset", "config" : { "Dist::Zilla::Plugin::Test::Perl::Critic::Subset" : { "finder" : [ ":ExecFiles", ":InstallModules", ":TestFiles" ] } }, "name" : "@Author::PERLANCAR/Test::Perl::Critic::Subset", "version" : "3.001.005" }, { "class" : "Dist::Zilla::Plugin::Test::Rinci", "name" : "@Author::PERLANCAR/Test::Rinci", "version" : "0.040" }, { "class" : "Dist::Zilla::Plugin::StaticInstall", "config" : { "Dist::Zilla::Plugin::StaticInstall" : { "dry_run" : 0, "mode" : "on" } }, "name" : "@Author::PERLANCAR/StaticInstall", "version" : "0.012" }, { "class" : "Dist::Zilla::Plugin::EnsureSQLSchemaVersionedTest", "name" : "@Author::PERLANCAR/EnsureSQLSchemaVersionedTest", "version" : "0.03" }, { "class" : "Dist::Zilla::Plugin::Acme::CPANModules::Blacklist", "name" : "@Author::PERLANCAR/Acme::CPANModules::Blacklist", "version" : "0.001" }, { "class" : "Dist::Zilla::Plugin::Prereqs::EnsureVersion", "name" : "@Author::PERLANCAR/Prereqs::EnsureVersion", "version" : "0.050" }, { "class" : "Dist::Zilla::Plugin::Prereqs::CheckCircular", "name" : "@Author::PERLANCAR/Prereqs::CheckCircular", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN::WWWPAUSESimple", "name" : "@Author::PERLANCAR/UploadToCPAN::WWWPAUSESimple", "version" : "0.04" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "TestRequires", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "runtime", "type" : "requires" } }, "name" : "Prereqs", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.017" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.017" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.017" } }, "x_authority" : "cpan:PERLANCAR", "x_contributors" : [ "Steven Haryanto (on PC) " ], "x_generated_by_perl" : "v5.34.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.26", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later", "x_static_install" : 1 } Text-ANSI-Util-0.233/t/0000775000175000017500000000000014104005531012002 5ustar u1u1Text-ANSI-Util-0.233/t/author-pod-syntax.t0000644000175000017500000000045414104005531015576 0ustar u1u1#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Text-ANSI-Util-0.233/t/01-latin.t0000644000175000017500000001666714104005531013532 0ustar u1u1#!perl use 5.010001; use strict; use warnings; use constant NL => "\n"; use Data::Dump qw(dump); use POSIX; use Test::More 0.98; use Text::ANSI::Util qw( ta_add_color_resets ta_detect ta_length ta_length_height ta_pad ta_split_codes ta_split_codes_single ta_strip ta_trunc ta_wrap ta_highlight ta_highlight_all ta_extract_codes ta_substr ); subtest "ta_detect" => sub { ok(!ta_detect("a"), 'neg 1'); ok(!ta_detect("\e"), 'neg 2'); ok( ta_detect("\e[0m"), 'pos 1'); ok( ta_detect("\e[31;47mhello\e[0m"), 'pos 2'); }; subtest "ta_strip" => sub { is(ta_strip(""), ""); is(ta_strip("hello"), "hello"); is(ta_strip("\e[31;47mhello\e[0m"), "hello"); }; subtest "ta_extract_codes" => sub { is(ta_extract_codes(""), ""); is(ta_extract_codes("hello"), ""); is(ta_extract_codes("\e[31;47mhello\e[0m"), "\e[31;47m\e[0m"); }; subtest "ta_split_codes" => sub { is_deeply([ta_split_codes("")], []); is_deeply([ta_split_codes("a")], ["a"]); is_deeply([ta_split_codes("a\e[31m")], ["a", "\e[31m"]); is_deeply([ta_split_codes("\e[31ma")], ["", "\e[31m", "a"]); is_deeply([ta_split_codes("\e[31ma\e[0m")], ["", "\e[31m", "a", "\e[0m"]); is_deeply([ta_split_codes("\e[31ma\e[0mb")], ["", "\e[31m", "a", "\e[0m", "b"]); is_deeply([ta_split_codes("\e[31m\e[0mb")], ["", "\e[31m\e[0m", "b"]); }; subtest "ta_split_codes_single" => sub { is_deeply([ta_split_codes_single("\e[31m\e[0mb")], ["", "\e[31m", "", "\e[0m", "b"]); }; subtest "ta_length" => sub { is(ta_length(""), 0); is(ta_length("hello"), 5); is(ta_length("\e[0m"), 0); is(ta_length("\e[31;47mhello\e[0m"), 5); }; subtest "ta_length_height" => sub { is_deeply(ta_length_height(""), [0, 0]); is_deeply(ta_length_height("\e[0m"), [0, 0]); is_deeply(ta_length_height(" "), [1, 1]); is_deeply(ta_length_height(" \n"), [1, 2]); is_deeply(ta_length_height("\e[31;47myellow\e[0m\nhello\n"), [6, 3]); }; # single paragraph my $txt1 = <<_; \e[31;47mI\e[0m dont wan't to go home. Where do you want to go? I'll keep you company. Mr Goh, I'm fine. You don't have to keep me company. _ #qq--------10--------20--------30--------40--------50 my $txt1w = qq|\e[31;47mI\e[0m dont wan't to go home. Where do you|.NL. qq|want to go? I'll keep you company. Mr|.NL. qq|Goh, I'm fine. You don't have to keep me|.NL. qq|company.|.NL; # multiple paragraph my $txt1b = <<_; \e[31;47mI\e[0m dont wan't to go home. Where do you want to go? I'll keep you company. Mr Goh, I'm fine. You don't have to keep me company. \e[31;47mI\e[0m dont wan't to go home. Where do you want to go? I'll keep you company. Mr Goh, I'm fine. You don't have to keep me company. _ #qq--------10--------20--------30--------40--------50 my $txt1bw = qq|\e[31;47mI\e[0m dont wan't to go home. Where do you|.NL. qq|want to go? I'll keep you company. Mr|.NL. qq|Goh, I'm fine. You don't have to keep me|.NL. qq|company.|.NL.NL. qq|\e[31;47mI\e[0m dont wan't to go home. Where do you|.NL. qq|want to go? I'll keep you company. Mr|.NL. qq|Goh, I'm fine. You don't have to keep me|.NL. qq|company.|.NL; # no terminating newline my $txt1c = "\e[31;47mI\e[0m dont wan't to go home. Where do you want to go? I'll keep you company. Mr Goh, I'm fine. You don't have to keep..."; #qq--------10--------20--------30--------40--------50 my $txt1cw = qq|\e[31;47mI\e[0m dont wan't to go home. Where do you|.NL. qq|want to go? I'll keep you company. Mr|.NL. qq|Goh, I'm fine. You don't have to keep...|; subtest "ta_wrap" => sub { my ($res, $cres); $res = ta_wrap($txt1 , 40); $cres = $txt1w; is($res, $cres, "single paragraph") or diag dump([split /^/, $cres], [split /^/, $res]); $res = ta_wrap($txt1b, 40); $cres = $txt1bw; is($res, $cres, "multiple paragraph") or diag dump([split /^/, $cres], [split /^/, $res]); $res = ta_wrap($txt1c, 40); $cres = $txt1cw; is($res, $cres, "no terminating newline") or diag dump([split /^/, $cres], [split /^/, $res]); $res = ta_wrap("x 12345678901234 x", 10); $cres = "x\n1234567890\n1234 x"; is($res, $cres, "truncate long word 1") or diag dump([split /^/, $cres], [split /^/, $res]); $res = ta_wrap("x \e[1m12345678901234\e[0m x", 10); $cres = "x\e[1m\e[0m\n\e[1m1234567890\e[0m\e[0m\n\e[1m1234\e[0m x"; is($res, $cres, "truncate long word 2") or diag dump([split /^/, $cres], [split /^/, $res]); $res = ta_wrap("\e[1m12345678901234\e[0m", 10); $cres = "\e[1m1234567890\e[0m\n\e[1m1234\e[0m"; is($res, $cres, "truncate long word 3 (broken in v0.08)") or diag dump([split /^/, $cres], [split /^/, $res]); $res = ta_wrap("x\n\e[1m\nx", 10); $cres = "x\n\n\e[1mx"; is($res, $cres, "color code in parabreak") or diag dump([split /^/, $cres], [split /^/, $res]); $res = ta_wrap("12345 123", 7, {flindent=>"xx", slindent=>"x"}); $cres = "xx12345\nx123"; is($res, $cres, "flindent & slindent opts (no color codes)") or diag dump([split /^/, $cres], [split /^/, $res]); $res = ta_wrap("\e[1m1\e[0m23\e[31m45 123\e[0m", 7, {flindent=>"xx", slindent=>"x"}); $cres = "xx\e[1m1\e[0m23\e[31m45\e[0m\n\e[31mx123\e[0m"; is($res, $cres, "flindent & slindent opts (with color codes)") or diag dump([split /^/, $cres], [split /^/, $res]); # XXX flindent & slindent deduced # XXX pad opt $res = ta_wrap("12345 123", 10, {return_stats=>1}); is_deeply($res, ["12345 123", {max_word_width=>5, min_word_width=>3}], "opt return_stats"); }; subtest "ta_trunc" => sub { my $t = "\e[31m1\e[32m2\e[33m3\e[0m4"; is(ta_trunc($t, 5), $t); is(ta_trunc($t, 4), $t); is(ta_trunc($t, 3), "\e[31m1\e[32m2\e[33m3\e[0m"); is(ta_trunc($t, 2), "\e[31m1\e[32m2\e[33m\e[0m"); is(ta_trunc($t, 1), "\e[31m1\e[32m\e[33m\e[0m"); is(ta_trunc($t, 0), "\e[31m\e[32m\e[33m\e[0m"); }; subtest "ta_pad" => sub { my $foo = "\e[31;47mfoo\e[0m"; is(ta_pad("" , 10), " ", "empty"); is(ta_pad("$foo", 10), "$foo "); is(ta_pad("$foo", 10, "l"), " $foo"); is(ta_pad("$foo", 10, "c"), " $foo "); is(ta_pad("$foo", 10, "r", "x"), "${foo}xxxxxxx"); is(ta_pad("${foo}12345678", 10), "${foo}12345678"); is(ta_pad("${foo}12345678", 10, undef, undef, 1), "${foo}1234567"); }; subtest "ta_highlight" => sub { is(ta_highlight("\e[1m\e[31m12345\e[32m64567\e[0m", "456", "\e[7m"), "\e[1m\e[31m123\e[7m45\e[0m\e[1m\e[31m\e[7m6\e[0m\e[1m\e[31m\e[32m4567\e[0m"); }; subtest "ta_highlight_all" => sub { is(ta_highlight_all("\e[1m\e[31m12345\e[32m674567\e[0m", "456", "\e[7m"), "\e[1m\e[31m123\e[7m45\e[0m\e[1m\e[31m\e[7m6\e[0m\e[1m\e[31m\e[32m7\e[7m456\e[0m\e[1m\e[31m\e[32m7\e[0m"); }; subtest "ta_add_color_resets" => sub { is_deeply([ta_add_color_resets("\e[31mred and \e[1mbold", "beureum", "merah\e[0m normal", "normale")], ["\e[31mred and \e[1mbold\e[0m", "\e[31m\e[1mbeureum\e[0m", "\e[31m\e[1mmerah\e[0m normal", "\e[0mnormale"]); }; subtest "ta_substr" => sub { diag dump(ta_substr("\e[31m1234\e[32m5678\e[0m", 2, 4, "foo")); is(ta_substr("\e[31m1234\e[32m5678\e[0m", 2, 4), "\e[31m34\e[32m56\e[0m"); is(ta_substr("\e[31m1234\e[32m5678\e[0m", 2, 4, "foo"), "\e[31m12\e[0mfoo\e[31m\e[32m78\e[0m"); }; DONE_TESTING: done_testing(); Text-ANSI-Util-0.233/t/author-pod-coverage.t0000644000175000017500000000053614104005531016044 0ustar u1u1#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Text-ANSI-Util-0.233/t/#01-basic.t#0000644000175000017500000000007014104005531013567 0ustar u1u1#!perl use strict; use warnings; use Test::More 0.98; Text-ANSI-Util-0.233/t/00-compile.t0000644000175000017500000000267414104005531014043 0ustar u1u1use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058 use Test::More; plan tests => 2 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'Text/ANSI/BaseUtil.pm', 'Text/ANSI/Util.pm' ); # no fake home requested my @switches = ( -d 'blib' ? '-Mblib' : '-Ilib', ); use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} } $^X, @switches, '-e', "require q[$lib]")) if $ENV{PERL_COMPILE_TEST_DEBUG}; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { +require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING}; Text-ANSI-Util-0.233/t/author-critic.t0000644000175000017500000000075714104005531014753 0ustar u1u1#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { print qq{1..0 # SKIP these tests are for testing by the author\n}; exit } } use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Perl::Critic::Subset 3.001.005 use Test::Perl::Critic (-profile => "") x!! -e ""; my $filenames = ['lib/Text/ANSI/BaseUtil.pm','lib/Text/ANSI/Util.pm']; unless ($filenames && @$filenames) { $filenames = -d "blib" ? ["blib"] : ["lib"]; } all_critic_ok(@$filenames); Text-ANSI-Util-0.233/LICENSE0000644000175000017500000004405314104005531012550 0ustar u1u1This software is copyright (c) 2021, 2016, 2015, 2014, 2013 by perlancar . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2021, 2016, 2015, 2014, 2013 by perlancar . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2021, 2016, 2015, 2014, 2013 by perlancar . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Text-ANSI-Util-0.233/lib/0000775000175000017500000000000014104005531012305 5ustar u1u1Text-ANSI-Util-0.233/lib/Text/0000775000175000017500000000000014104005531013231 5ustar u1u1Text-ANSI-Util-0.233/lib/Text/ANSI/0000775000175000017500000000000014104005531013763 5ustar u1u1Text-ANSI-Util-0.233/lib/Text/ANSI/BaseUtil.pm0000644000175000017500000007150014104005531016032 0ustar u1u1package Text::ANSI::BaseUtil; our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY our $DATE = '2021-08-08'; # DATE our $DIST = 'Text-ANSI-Util'; # DIST our $VERSION = '0.233'; # VERSION use 5.010001; use strict; use warnings; use List::Util qw(min max); our $re = qr/\e\[[0-9;]+m/s; our $re_mult = qr/(?:\e\[[0-9;]+m)+/s; sub ta_detect { my $text = shift; $text =~ $re ? 1:0; } sub ta_length { my $text = shift; length(ta_strip($text)); } sub _ta_length_height { my ($is_mb, $text) = @_; my $num_lines = 0; my @lens; for my $e (split /(\r?\n)/, ta_strip($text)) { if ($e =~ /\n/) { $num_lines++; next; } $num_lines = 1 if $num_lines == 0; push @lens, $is_mb ? Text::WideChar::Util::mbswidth($e) : length($e); } [max(@lens) // 0, $num_lines]; } sub ta_length_height { _ta_length_height(0, @_); } sub ta_mbswidth_height { _ta_length_height(1, @_); } sub ta_strip { my $text = shift; $text =~ s/$re//go; $text; } sub ta_extract_codes { my $text = shift; my $res = ""; $res .= $1 while $text =~ /($re_mult)/go; $res; } sub ta_split_codes { my $text = shift; return split(/($re_mult)/o, $text); } sub ta_split_codes_single { my $text = shift; return split(/($re)/o, $text); } # same like _ta_mbswidth, but without handling multiline text sub _ta_mbswidth0 { my $text = shift; Text::WideChar::Util::mbswidth(ta_strip($text)); } sub ta_mbswidth { my $text = shift; ta_mbswidth_height($text)->[0]; } sub _indent_width { my ($indent, $tab_width) = @_; my $w = 0; for (split //, $indent) { if ($_ eq "\t") { # go to the next tab $w = $tab_width * (int($w/$tab_width) + 1); } else { $w += 1; } } $w; } sub _ta_wrap { my ($is_mb, $text, $width, $opts) = @_; $width //= 80; $opts //= {}; # basically similar to Text::WideChar::Util's algorithm. we adjust for # dealing with ANSI codes by splitting codes first (to easily do color # resets/replays), then grouping into words and paras, then doing wrapping. my $_re1 = $is_mb ? qr/($Text::WideChar::Util::re_cjk+)|(\S+)|(\s+)/ : qr/()(\S+)|(\s+)/; my $_re2 = $is_mb ? qr/($Text::WideChar::Util::re_cjk_class+)| ($Text::WideChar::Util::re_cjk_negclass+)/x : undef; my @termst; # store term type, 's' (spaces), 'w' (word), 'c' (cjk word) or # 'p' (parabreak) my @terms; # store the text (w/ codes); for ws, only store the codes my @pterms; # store the plaintext ver, but only for ws to check parabreak my @termsw; # store width of each term, only for non-ws my @termsc; # store color replay code { my @ch = ta_split_codes_single($text); my $crcode = ""; # code for color replay to be put at the start of line my $term = ''; my $pterm = ''; my $prev_type = ''; while (my ($pt, $c) = splice(@ch, 0, 2)) { #use Data::Dump; print "D:chunk: "; dd [$pt, $c]; # split into (CJK and non-CJK) words and spaces. my @s; # (WORD1, TYPE, ...) where type is 's' for space, 'c' for # CJK word, or 'w' for non-CJK word while ($pt =~ /$_re1/g) { if ($is_mb && $1) { push @s, $1, 'c'; } elsif ($3) { push @s, $3, 's'; } else { if ($is_mb) { my $pt2 = $2; while ($pt2 =~ /$_re2/g) { if ($1) { push @s, $1, 'c'; } else { push @s, $2, 'w'; } } } else { push @s, $2, 'w'; } } } #use Data::Dump; say "D:s=",Data::Dump::dump(\@s); my $only_code; $only_code = 1 if !@s; while (1) { my ($s, $s_type) = splice @s, 0, 2; $s_type //= ''; last unless $only_code || defined($s); # empty text, only code if ($only_code) { $s = ""; $term .= $c if defined $c; } #say "D:s=[$s] prev_type=$prev_type \@ch=",~~@ch," \@s=",~~@s; if ($s_type && $s_type ne 's') { if ($prev_type eq 's') { #say "D:found word, completed previous ws [$term]"; push @termst, 's'; push @terms , $term; push @pterms, $pterm; push @termsw, undef; push @termsc, $crcode; # start new word $pterm = ''; $term = ''; } elsif ($prev_type && $prev_type ne $s_type) { #say "D:found a ".($s_type eq 'c' ? 'CJK':'non-CJK')." word, completed previous ".($prev_type eq 'c' ? 'CJK':'non-CJK')." word [$term]"; push @termst, $prev_type; push @terms , $term; push @pterms, $pterm; push @termsw, $is_mb ? Text::WideChar::Util::mbswidth($pterm):length($pterm); push @termsc, $crcode; # start new word $pterm = ''; $term = ''; } $pterm .= $s; $term .= $s; $term .= $c if defined($c) && !@s; if (!@s && !@ch) { #say "D:complete word because this is the last token"; push @termst, $s_type; push @terms , $term; push @pterms, ""; push @termsw, $is_mb ? Text::WideChar::Util::mbswidth($pterm):length($pterm); push @termsc, $crcode; } } elsif (length($s)) { if ($prev_type ne 's') { #say "D:found ws, completed previous word [$term]"; push @termst, $prev_type; push @terms , $term; push @pterms, ""; push @termsw, $is_mb ? Text::WideChar::Util::mbswidth($pterm):length($pterm); push @termsc, $crcode; # start new ws $pterm = ''; $term = ''; } $pterm .= $s; $term .= $c if defined($c) && !@s; if (!@s && !@ch) { #say "D:complete ws because this is the last token"; push @termst, 's'; push @terms , $term; push @pterms, $pterm; push @termsw, undef; push @termsc, $crcode; } } $prev_type = $s_type; if (!@s) { if (defined($c) && $c =~ /m\z/) { if ($c eq "\e[0m") { #say "D:found color reset, emptying crcode"; $crcode = ""; } elsif ($c =~ /m\z/) { #say "D:adding to crcode"; $crcode .= $c; } } last if $only_code; } } # splice @s } # splice @ch } # mark parabreaks { my $i = 0; while ($i < @pterms) { if ($termst[$i] eq 's') { if ($pterms[$i] =~ /[ \t]*(\n(?:[ \t]*\n)+)([ \t]*)/) { #say "D:found parabreak"; $pterms[$i] = $1; $termst[$i] = 'p'; if ($i < @pterms-1) { # stick color code to the beginning of next para $terms [$i+1] = $terms[$i] . $terms [$i+1]; $terms [$i] = ""; } if (length $2) { #say "D:found space after parabreak, splitting"; splice @termst, $i+1, 0, "s"; splice @terms , $i+1, 0, ""; splice @pterms, $i+1, 0, $2; splice @termsw, $i+1, 0, undef; splice @termsc, $i+1, 0, $termsc[$i]; $i += 2; next; } } } $i++; } } #use Data::Dump::Color; my @d; for (0..$#terms) { push @d, {type=>$termst[$_], term=>$terms[$_], pterm=>$pterms[$_], termc=>$termsc[$_], termw=>$termsw[$_], } } dd \@d; #return; #use Data::Dump; say "D:termst=".Data::Dump::dump(\@termst); #use Data::Dump; say "D:terms =".Data::Dump::dump(\@terms); #use Data::Dump; say "D:pterms=".Data::Dump::dump(\@pterms); #use Data::Dump; say "D:termsw=".Data::Dump::dump(\@termsw); #use Data::Dump; say "D:termsc=".Data::Dump::dump(\@termsc); my ($maxww, $minww); # now we perform wrapping my @res; { my $tw = $opts->{tab_width} // 8; die "Please specify a positive tab width" unless $tw > 0; my $optfli = $opts->{flindent}; my $optfliw; $optfliw = $is_mb ? Text::WideChar::Util::_mbs_indent_width($optfli, $tw) : _indent_width($optfli, $tw) if defined $optfli; my $optsli = $opts->{slindent}; my $optsliw; $optsliw = $is_mb ? Text::WideChar::Util::_mbs_indent_width($optsli, $tw) : _indent_width($optsli, $tw) if defined $optsli; my $optkts = $opts->{keep_trailing_space} // 0; my $pad = $opts->{pad}; my $x = 0; my $y = 0; my ($fli, $sli, $fliw, $sliw); my $is_parastart = 1; my $line_has_word = 0; my ($termt, $prev_t); TERM: for my $i (0..$#terms) { $prev_t = $termt if $i; $termt = $termst[$i]; my $term = $terms[$i]; my $pterm = $pterms[$i]; my $termw = $termsw[$i]; my $crcode = $i > 0 ? $termsc[$i-1] : ""; #say "D:term=[", ($termt eq 'w' ? $term : $pterm), "] ($termt)"; # end of paragraph if ($termt eq 'p') { my $numnl = 0; $numnl++ while $pterm =~ /\n/g; for (1..$numnl) { push @res, "\e[0m" if $crcode && $_ == 1; push @res, " " x ($width-$x) if $pad; push @res, "\n"; $x = 0; $y++; } $line_has_word = 0; $x = 0; $is_parastart = 1; next TERM; } if ($is_parastart) { unless (defined $fli) { # this is the start of paragraph, determine indents $fli = $optfli; $fliw = $optfliw; if ($termt eq 's') { $fli //= $pterm; $fliw //= $is_mb ? Text::WideChar::Util::_mbs_indent_width($fli, $tw) : _indent_width($fli, $tw); } else { $fli //= ""; $fliw //= 0; } $sli = $optsli; $sliw = $optsliw; unless (defined $sli) { my $j = $i; while ($j < @terms && $termst[$j] ne 'p') { if ($termst[$j] eq 's') { if ($pterms[$j] =~ /\n([ \t]+)/) { $sli = $1; $sliw = $is_mb ? Text::WideChar::Util::_mbs_indent_width($sli, $tw) : _indent_width($sli, $tw); last; } } $j++; } } $sli //= ""; $sliw //= 0; die "Subsequent indent must be less than width" if $sliw >= $width; } #say "D:inserting the fli [$fli] ($fliw)"; push @res, $fli; $x += $fliw; } # parastart $is_parastart = 0; if ($termt eq 's') { # just print the codes push @res, $term; # maintain terminating newline if ($pterm =~ /\n/ && $i == $#terms) { push @res, "\e[0m" if $crcode; push @res, " " x ($width-$x) if $pad; push @res, "\n"; $line_has_word = 0; } } if ($termt ne 's') { # we need to chop long words my @words; my @wordsw; my @wordst; # c if cjk, w if not my @wordswsb; # whether there are ws before the word my $j = 0; my $c = ""; # see below for explanation while (1) { $j++; # most words shouldn't be that long. and we don't need to # truncate long CJK word first here because it will get # truncated later. if ($termw <= $width-$sliw || $termt eq 'c') { push @words , $c . $term; push @wordsw , $termw; push @wordst , $termt; push @wordswsb, ($prev_t && $prev_t eq 's')?1:0; last; } #use Data::Dump; print "D:truncating long word "; dd $term; my $res = $is_mb ? ta_mbtrunc($term, $width-$sliw, 1) : ta_trunc($term, $width-$sliw, 1); my ($tword, $twordw); if ($j == 1) { $tword = $res->[0]; $twordw = $res->[1]; } else { # since ta_{,mb}trunc() adds the codes until the end of # the word, to avoid messing colors, for the second word # and so on we need to replay colors by prefixing with: # \e[0m (reset) + $crcode + (all the codes from the # start of the long word up until the truncated # position, stored in $c). # # there might be faster way, but it is expected that # long words are not that common. $tword = ($crcode ? "\e[0m" . $crcode : "") . $c . $res->[0]; $twordw = $res->[1]; } $c .= ta_extract_codes(substr($term, 0, $res->[2])); #use Data::Dump; print "D:truncated word is "; dd $tword; push @words , $tword; push @wordsw , $twordw; push @wordst , $termt; push @wordswsb, $j == 1 ? (($prev_t && $prev_t eq 's')?1:0) : 0; $term = substr($term, $res->[2]); $termw = $is_mb ? _ta_mbswidth0($term) : ta_length($term); } #use Data::Dump; print "D:words="; dd \@words; print "D:wordsw="; dd \@wordsw; print "D:wordswsb="; dd \@wordswsb; # the core of the wrapping algo for my $word (@words) { my $wordw = shift @wordsw; my $wordt = shift @wordst; my $ws_before = shift @wordswsb; #say "D:x=$x word=$word wordw=$wordw wordt=$wordt ws_before=$ws_before line_has_word=$line_has_word width=$width"; $maxww = $wordw if !defined($maxww) || $maxww < $wordw; $minww = $wordw if !defined($minww) || $minww > $wordw; if ($x + ($line_has_word ? 1:0) + $wordw <= $width) { if ($line_has_word && $ws_before) { push @res, " "; $x++; } push @res, $word; $x += $wordw; } else { # line break while (1) { if ($wordt eq 'c') { # a CJK word can be line-broken my $res; if ($ws_before) { $res = ta_mbtrunc($word, $width-$x-1, 1); push @res, " ", $res->[0]; } else { $res = ta_mbtrunc($word, $width-$x, 1); push @res, $res->[0]; } #say "D:truncated CJK word: $word (".length($word)."), ".($width-$x)." -> $res->[0] (".length($res->[0]).") & $res->[1], remaining=$res->[3] (".length($res->[3]).")"; $word = $res->[3]; $wordw = _ta_mbswidth0($res->[3]); } else { push @res, "\e[0m" if $crcode; } push @res, " " x ($width-$x) if $pad; push @res, " " if $ws_before && $optkts; push @res, "\n"; $y++; push @res, $crcode; push @res, $sli; if ($sliw + $wordw <= $width) { push @res, $word; $x = $sliw + $wordw; last; } else { # word still too long, break again $x = $sliw; $ws_before = 0; } } } $line_has_word++; } } } # for term push @res, " " x ($width-$x) if $line_has_word && $pad; } if ($opts->{return_stats}) { return [join("", @res), { max_word_width => $maxww, min_word_width => $minww, }]; } else { return join("", @res); } } sub ta_wrap { _ta_wrap(0, @_); } sub ta_mbwrap { _ta_wrap(1, @_); } sub _ta_pad { my ($is_mb, $text, $width, $which, $padchar, $is_trunc) = @_; if ($which) { $which = substr($which, 0, 1); } else { $which = "r"; } $padchar //= " "; my $w = $is_mb ? _ta_mbswidth0($text) : ta_length($text); if ($is_trunc && $w > $width) { my $res = $is_mb ? ta_mbtrunc($text, $width, 1) : ta_trunc($text, $width, 1); $text = $res->[0] . ($padchar x ($width-$res->[1])); } else { if ($which eq 'l') { $text = ($padchar x ($width-$w)) . $text; } elsif ($which eq 'c') { my $n = int(($width-$w)/2); $text = ($padchar x $n) . $text . ($padchar x ($width-$w-$n)); } else { $text .= ($padchar x ($width-$w)) if $width > $w; } } $text; } sub ta_pad { _ta_pad(0, @_); } sub ta_mbpad { _ta_pad(1, @_); } sub _ta_trunc { my ($is_mb, $text, $width, $return_extra) = @_; # return_extra (undocumented): if set to 1, will return [truncated_text, # visual width, length(chars) up to truncation point, rest of the text not # included] my $w = $is_mb ? _ta_mbswidth0($text) : ta_length($text); if ($w <= $width) { return $return_extra ? [$text, $w, length($text), ''] : $text; } my @p = ta_split_codes_single($text); my $res = ''; my $append = 1; # whether we should add more text my $code4rest = ''; my $rest = ''; $w = 0; my $c = 0; #use Data::Dump; dd \@p; while (my ($t, $ansi) = splice @p, 0, 2) { #say "D: t=<$t>, \@p=", ~~@p, ", code4rest=<$code4rest>, rest=<$rest>"; if ($append) { my $tw = $is_mb ? Text::WideChar::Util::mbswidth($t) : length($t); #say "D: tw=$tw"; if ($w+$tw <= $width) { $res .= $t; $w += $tw; $c += length($t); $append = 0 if $w == $width; #say "D:end1" unless $append; } else { my $tres = $is_mb ? Text::WideChar::Util::mbtrunc($t, $width-$w, 1) : [substr($t, 0, $width-$w), $width-$w, $width-$w]; #use Data::Dump; dd $tres; $res .= $tres->[0]; $w += $tres->[1]; $c += $tres->[2]; $rest = substr($t, $tres->[2]); $append = 0; #say "D:end2"; } } else { $rest .= $t; } if (defined $ansi) { if ($append) { if ($ansi eq "\e[0m") { #say "D:found color reset, resetting code4rest"; $c = length($ansi); $code4rest = $ansi; } else { $c += length($ansi); $code4rest .= $ansi; } $res .= $ansi; } else { $res .= $ansi; $rest .= $ansi; } } } # ta_trunc/ta_mbtrunc currently adds unpruned color codes at the end of # truncated string. pruned meaning strings of color codes right before reset # code is removed, e.g. \e[1m\e[30m...\e[0m becomes \e[0m. you might want to # prune the result of trunc using _ta_prune_codes. if ($return_extra) { return [$res, $w, $c, $code4rest . $rest]; } else { return $res; } } sub _ta_prune_codes { my $text = shift; $text =~ s/($re_mult)\e\[0m/\e\[0m/g; $text; } sub ta_trunc { _ta_trunc(0, @_); } sub ta_mbtrunc { _ta_trunc(1, @_); } sub _ta_highlight { my ($is_all, $text, $needle, $color) = @_; # break into chunks my (@chptext, @chcode, @chsavedc); # chunk plain texts, codes, saved codes my $sc = ""; my $plaintext = ""; my @ch = ta_split_codes_single($text); while (my ($pt, $c) = splice(@ch, 0, 2)) { push @chptext , $pt; push @chcode , $c; push @chsavedc, $sc; $plaintext .= $pt; if (defined($c) && $c =~ /m\z/) { if ($c eq "\e[0m") { $sc = ""; } elsif ($c =~ /m\z/) { $sc .= $c; } } } #use Data::Dump; print "\@chptext: "; dd \@chptext; print "\@chcode: "; dd \@chcode; print "\@chsavedc: "; dd \@chsavedc; # gather a list of needles to highlight, with their positions my (@needle, @npos); if (ref($needle) eq 'Regexp') { my @m = $plaintext =~ /$needle/g; return $text unless @m; my $pos = 0; while ($pos < length($plaintext)) { my @pt; for (@m) { my $p = index($plaintext, $_, $pos); push @pt, [$p, $_] if $p >= 0; } last unless @pt; my $pmin = $pt[0][0]; my $t = $pt[0][1]; for (@pt) { if ($pmin > $_->[0] || $pmin==$_->[0] && length($t) < length($_->[1])) { $pmin = $_->[0]; $t = $_->[1]; } } push @needle, $t; push @npos , $pmin; last unless $is_all; $pos = $pmin + length($t); } } else { my $pos = 0; while (1) { #say "D:finding '$needle' in '$plaintext' from pos '$pos'"; my $p = index($plaintext, $needle, $pos); last if $p < 0; push @needle, $needle; push @npos , $p; last unless $is_all; $pos = $p + length($needle); last if $pos >= length($plaintext); } return $text unless @needle; } #use Data::Dump; print "\@needle: "; dd \@needle; print "\@npos: "; dd \@npos; my @res; my $found = 1; my $pos = 0; my $i = 0; my $curneed = shift @needle; my $npos = shift @npos; CHUNK: while (1) { last if $i >= @chptext; my $pos2 = $pos+length($chptext[$i])-1; my $npos2 = $npos+length($curneed)-1; #say "D: chunk=[$chptext[$i]], npos=$npos, npos2=$npos2, pos=$pos, pos2=$pos2"; if ($pos > $npos2 || $pos2 < $npos || !$found) { #say "D:inserting chunk: [$chptext[$i]]"; # no need to highlight push @res, $chptext[$i]; push @res, $chcode[$i] if defined $chcode[$i]; goto L1; } # there is chunk text at the left of needle? if ($pos < $npos) { my $pre = substr($chptext[$i], 0, $npos-$pos); #say "D:inserting pre=[$pre]"; push @res, $pre; } my $npart = substr($curneed, max(0, $pos-$npos), min($pos2, $npos2)-max($pos, $npos)+1); if (length($npart)) { #say "D:inserting npart=[$npart]"; push @res, $color, $npart; push @res, "\e[0m"; #use Data::Dump; dd [$chsaved[$i], $chcode[$i]]; push @res, $chsavedc[$i]; } # is there chunk text at the right of needle? if ($npos2 <= $pos2) { #say "D:We have run past current needle [$curneed]"; my $post = substr($chptext[$i], $npos2-$pos+1); if (@needle) { $curneed = shift @needle; $npos = shift @npos; #say "D:Finding the next needle ($curneed) at pos $npos"; $pos = $npos2+1; $chptext[$i] = $post; $found = 1; redo CHUNK; } else { # we're done finding needle $found = 0; } if (!$found) { #say "D:inserting post=[$post]"; push @res, $post; push @res, $chcode[$i] if defined $chcode[$i]; } } L1: $pos = $pos2+1; $i++; } join "", @res; } sub ta_highlight { _ta_highlight(0, @_); } sub ta_highlight_all { _ta_highlight(1, @_); } sub ta_add_color_resets { my (@text) = @_; my @res; my $i = 0; my $savedc = ""; for my $text (@text) { $i++; my $newt = $i > 1 && !$savedc ? "\e[0m" : $savedc; # break into chunks my @ch = ta_split_codes_single($text); while (my ($t, $c) = splice(@ch, 0, 2)) { $newt .= $t; if (defined($c) && $c =~ /m\z/) { $newt .= $c; if ($c eq "\e[0m") { $savedc = ""; } elsif ($c =~ /m\z/) { $savedc .= $c; } } } $newt .= "\e[0m" if $savedc && $i < @text; push @res, $newt; } @res; } sub _ta_substr { my $is_mb = shift; my $str = shift; my $pos = shift; my $len = shift; my $res1 = _ta_trunc($is_mb, $str, $pos, 1); my $res2 = _ta_trunc($is_mb, $res1->[3], $len, 1); if (@_) { # left + replacement + right return _ta_prune_codes($res1->[0] . $_[0] . $res2->[3]); } else { return _ta_prune_codes($res2->[0]); } } sub ta_substr { _ta_substr(0, @_); } sub ta_mbsubstr { _ta_substr(1, @_); } 1; # ABSTRACT: Base for Text::ANSI::{Util,WideUtil} __END__ =pod =encoding UTF-8 =head1 NAME Text::ANSI::BaseUtil - Base for Text::ANSI::{Util,WideUtil} =head1 VERSION This document describes version 0.233 of Text::ANSI::BaseUtil (from Perl distribution Text-ANSI-Util), released on 2021-08-08. =for Pod::Coverage .* =head1 HOMEPAGE Please visit the project's homepage at L. =head1 SOURCE Source repository is at L. =head1 BUGS Please report any bugs or feature requests on the bugtracker website L When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 AUTHOR perlancar =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2021, 2016, 2015, 2014, 2013 by perlancar . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Text-ANSI-Util-0.233/lib/Text/ANSI/Util.pm0000644000175000017500000003132114104005531015234 0ustar u1u1package Text::ANSI::Util; our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY our $DATE = '2021-08-08'; # DATE our $DIST = 'Text-ANSI-Util'; # DIST our $VERSION = '0.233'; # VERSION use 5.010001; use strict 'subs', 'vars'; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( ta_add_color_resets ta_detect ta_extract_codes ta_highlight ta_highlight_all ta_length ta_length_height ta_pad ta_split_codes ta_split_codes_single ta_strip ta_substr ta_trunc ta_wrap ); use Text::ANSI::BaseUtil (); our $re = $Text::ANSI::BaseUtil::re; *{$_} = \&{"Text::ANSI::BaseUtil::$_"} for @EXPORT_OK; 1; # ABSTRACT: Routines for text containing ANSI color codes __END__ =pod =encoding UTF-8 =head1 NAME Text::ANSI::Util - Routines for text containing ANSI color codes =head1 VERSION This document describes version 0.233 of Text::ANSI::Util (from Perl distribution Text-ANSI-Util), released on 2021-08-08. =head1 SYNOPSIS use Text::ANSI::Util qw( ta_add_color_resets ta_detect ta_extract_codes ta_highlight ta_highlight_all ta_length ta_length_height ta_pad ta_split_codes ta_split_codes_single ta_strip ta_substr ta_trunc ta_wrap ); # detect whether text has ANSI color codes? say ta_detect("red"); # => false say ta_detect("\e[31mred"); # => true # calculate length of text (excluding the ANSI color codes) say ta_length("red"); # => 3 say ta_length("\e[31mred"); # => 3 # strip ANSI color codes say ta_strip("\e[31mred"); # => "red" # split codes (ANSI color codes are always on the even positions) my @parts = ta_split_codes("\e[31mred"); # => ("", "\e[31m", "red") # wrap text to a certain column width, handle ANSI color codes say ta_wrap("....", 40); # pad (left, right, center) text to a certain width say ta_pad("foo", 10); # => "foo " say ta_pad("foo", 10, "left"); # => " foo" say ta_pad("foo\nbarbaz\n", 10, "center", "."); # => "...foo....\n..barbaz..\n" # truncate text to a certain width while still passing ANSI color codes use Term::ANSIColor; my $text = color("red")."red text".color("reset"); # => "\e[31mred text\e[0m" say ta_trunc($text, 5); # => "\e[31mred t\e[0m" # highlight the first occurrence of some string within text say ta_highlight("some text", "ome", "\e[7m\e[31m"); # ditto, but highlight all occurrences say ta_highlight_all(...); # get substring my $substr = ta_substr("...", $pos, $len); # return text but with substring replaced with replacement say ta_substr("...", $pos, $len, $replacement); =head1 DESCRIPTION This module provides routines for dealing with text that contains ANSI color codes, e.g. for determining its length/width (excluding the color codes), stripping the color codes, extracting the color codes, and so on. For functions that support wide characters, see L. Current caveats: =over =item * Other ANSI codes (non-color codes) are ignored These are codes like for altering cursor positions, etc. =item * Single-character CSI (control sequence introducer) currently ignored Only C (two-character CSI) is currently parsed. BTW, in ASCII terminals, single-character CSI is C<0x9b>. In UTF-8 terminals, it is C<0xc2, 0x9b> (2 bytes). =item * Private-mode- and trailing-intermediate character currently not parsed =item * Only color reset code \e[0m is recognized For simplicity, currently multiple SGR parameters inside a single ANSI color code is not parsed. This means that color reset code like C<\e[1;0m> or C<\e[31;47;0m> is not recognized, only C<\e[0m> is. I believe this should not be a problem with most real-world text out there. =back =head1 CONTRIBUTOR =for stopwords Steven Haryanto (on PC) Steven Haryanto (on PC) =head1 FUNCTIONS =head2 ta_add_color_resets(@text) => LIST Make sure that a color reset command (add C<\e[0m>) to the end of each element and a replay of all the color codes from the previous element, from the last color reset) to the start of the next element, and so on. Return the new list. This makes each element safe to be combined with other array of text into a single line, e.g. in a multicolumn/tabular layout. An example: Without color resets: my @col1 = split /\n/, "\e[31mred\nmerah\e[0m"; my @col2 = split /\n/, "\e[32mgreen\e[1m\nhijau tebal\e[0m"; printf "%s | %s\n", $col1[0], $col2[0]; printf "%s | %s\n", $col1[1], $col2[1]; the printed output: \e[31mred | \e[32mgreen merah\e[0m | \e[1mhijau tebal\e[0m The C text on the second line will become green because of the effect of the last color command printed (C<\e[32m>). However, with ta_add_color_resets(): my @col1 = ta_add_color_resets(split /\n/, "\e[31mred\nmerah\e[0m"); my @col2 = ta_add_color_resets(split /\n/, "\e[32mgreen\e[1m\nhijau tebal\e[0m"); printf "%s | %s\n", $col1[0], $col2[0]; printf "%s | %s\n", $col1[1], $col2[1]; the printed output (C<< <...> >>) marks the code added by ta_add_color_resets(): \e[31mred<\e[0m> | \e[32mgreen\e[1m<\e[0m> <\e[31m>merah\e[0m | <\e[32m\e[1m>hijau tebal\e[0m All the cells are printed with the intended colors. =head2 ta_detect($text) => BOOL Return true if C<$text> contains ANSI color codes, false otherwise. =head2 ta_extract_codes($text) => STR This is the opposite of C, return only the ANSI codes in C<$text>. =head2 ta_highlight($text, $needle, $color) => STR Highlight the first occurrence of C<$needle> in C<$text> with <$color>, taking care not to mess up existing colors. C<$needle> can be a string or a Regexp object. Implementation note: to not mess up colors, we save up all color codes from the last reset (C<\e[0m>) before inserting the highlight color + highlight text. Then we issue C<\e[0m> and the saved up color code to return back to the color state before the highlight is inserted. This is the same technique as described in C. =head2 ta_highlight_all($text, $needle, $color) => STR Like C, but highlight all occurrences instead of only the first. =head2 ta_length($text) => INT Count the number of characters in $text, while ignoring ANSI color codes. Equivalent to C<< length(ta_strip($text)) >>. See also: C in L. =head2 ta_length_height($text) => [INT, INT] Like C, but also gives height (number of lines). For example, C<< ta_length_height("foobar\nb\n") >> gives C<[6, 3]>. See also: C in L. =head2 ta_pad($text, $width[, $which[, $padchar[, $truncate]]]) => STR Return C<$text> padded with C<$padchar> to C<$width> columns. C<$which> is either "r" or "right" for padding on the right (the default if not specified), "l" or "left" for padding on the right, or "c" or "center" or "centre" for left+right padding to center the text. C<$padchar> is whitespace if not specified. It should be string having the width of 1 column. Does *not* handle multiline text; you can split text by C yourself. See also: C in L. =head2 ta_split_codes($text) => LIST Split C<$text> to a list containing alternating ANSI color codes and text. ANSI color codes are always on the second element, fourth, and so on. Example: ta_split_codes(""); # => () ta_split_codes("a"); # => ("a") ta_split_codes("a\e[31m"); # => ("a", "\e[31m") ta_split_codes("\e[31ma"); # => ("", "\e[31m", "a") ta_split_codes("\e[31ma\e[0m"); # => ("", "\e[31m", "a", "\e[0m") ta_split_codes("\e[31ma\e[0mb"); # => ("", "\e[31m", "a", "\e[0m", "b") ta_split_codes("\e[31m\e[0mb"); # => ("", "\e[31m\e[0m", "b") so you can do something like: my @parts = ta_split_codes($text); while (my ($text, $ansicode) = splice(@parts, 0, 2)) { ... } =head2 ta_split_codes_single($text) => LIST Like C but each ANSI color code is split separately, instead of grouped together. This routine is currently used internally e.g. for C and C to trace color reset/replay codes. =head2 ta_strip($text) => STR Strip ANSI color codes from C<$text>, returning the stripped text. =head2 ta_substr($text, $pos, $len[ , $replacement ]) => STR A bit like Perl's C. If C<$replacement> is not specified, will return the substring. If C<$replacement> is specified, will return $text with the substring replaced by C<$replacement>. See also: C in L. =head2 ta_trunc($text, $width) => STR Truncate C<$text> to C<$width> columns while still including all the ANSI color codes. This ensures that truncated text still reset colors, etc. Does *not* handle multiline text; you can split text by C yourself. See also: C in L. =head2 ta_wrap($text, $width, \%opts) => STR Like L's C except handles ANSI color codes. Perform color reset at the end of each line and a color replay at the start of subsequent line so the text is safe for combining in a multicolumn/tabular layout. Options: =over =item * flindent => STR First line indent. Currently must not contain ANSI color codes or wide characters. =item * slindent => STR Subsequent line indent. Currently must not contain ANSI color codes or wide characters. =item * tab_width => INT (default: 8) =item * pad => BOOL (default: 0) If set to true, will pad each line to C<$width>. This is convenient if you need the lines padded, saves calls to ta_pad(). =item * return_stats => BOOL (default: 0) If set to true, then instead of returning the wrapped string, function will return C<< [$wrapped, $stats] >> where C<$stats> is a hash containing some information like C, C. =item * keep_trailing_space => BOOL (default: 0) If set to true, then trailing space that separates words will be kept at the end of wrapped lines. This option is useful if you want to rejoin the lines later. Without this option set to true, wrapping this line at width=4 (quotes shown): "some long line" will result in: "some" "long" "line" While if this option is set to true, the result will be: "some " "long " "line" =back Performance: ~500/s on my Core i5 1.7GHz laptop for a ~1KB of text (with zero to moderate amount of color codes). See also: C in L. =head1 FAQ =over 11 =back BEGIN_BLOCK: why_split =head2 Why split functionalities of wide character and color support into multiple modules/distributions? Performance (see numbers in the function description), dependency (L is used for wide character support), and overhead (loading Unicode::GCString). =over 11 =back END_BLOCK: why_split =head2 How do I highlight a string case-insensitively? You can currently use a regex for the C<$needle> and use the C modifier. Example: use Term::ANSIColor; ta_highlight($text, qr/\b(foo)\b/i, color("bold red")); =head1 HOMEPAGE Please visit the project's homepage at L. =head1 SOURCE Source repository is at L. =head1 BUGS Please report any bugs or feature requests on the bugtracker website L When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 SEE ALSO L provides padding function for strings that do not contain ASCII escape codes nor wide characters. L provides some other functions for strings that do not contain ASCII escape codes nor wide characters. L provides utilities for strings that do not contain ANSI escape codes I contain wide characters. L provides utilities for strings that contain ANSI escape codes I wide characters. =head1 AUTHOR perlancar =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2021, 2016, 2015, 2014, 2013 by perlancar . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Text-ANSI-Util-0.233/README0000644000175000017500000003016114104005531012416 0ustar u1u1NAME Text::ANSI::Util - Routines for text containing ANSI color codes VERSION This document describes version 0.233 of Text::ANSI::Util (from Perl distribution Text-ANSI-Util), released on 2021-08-08. SYNOPSIS use Text::ANSI::Util qw( ta_add_color_resets ta_detect ta_extract_codes ta_highlight ta_highlight_all ta_length ta_length_height ta_pad ta_split_codes ta_split_codes_single ta_strip ta_substr ta_trunc ta_wrap ); # detect whether text has ANSI color codes? say ta_detect("red"); # => false say ta_detect("\e[31mred"); # => true # calculate length of text (excluding the ANSI color codes) say ta_length("red"); # => 3 say ta_length("\e[31mred"); # => 3 # strip ANSI color codes say ta_strip("\e[31mred"); # => "red" # split codes (ANSI color codes are always on the even positions) my @parts = ta_split_codes("\e[31mred"); # => ("", "\e[31m", "red") # wrap text to a certain column width, handle ANSI color codes say ta_wrap("....", 40); # pad (left, right, center) text to a certain width say ta_pad("foo", 10); # => "foo " say ta_pad("foo", 10, "left"); # => " foo" say ta_pad("foo\nbarbaz\n", 10, "center", "."); # => "...foo....\n..barbaz..\n" # truncate text to a certain width while still passing ANSI color codes use Term::ANSIColor; my $text = color("red")."red text".color("reset"); # => "\e[31mred text\e[0m" say ta_trunc($text, 5); # => "\e[31mred t\e[0m" # highlight the first occurrence of some string within text say ta_highlight("some text", "ome", "\e[7m\e[31m"); # ditto, but highlight all occurrences say ta_highlight_all(...); # get substring my $substr = ta_substr("...", $pos, $len); # return text but with substring replaced with replacement say ta_substr("...", $pos, $len, $replacement); DESCRIPTION This module provides routines for dealing with text that contains ANSI color codes, e.g. for determining its length/width (excluding the color codes), stripping the color codes, extracting the color codes, and so on. For functions that support wide characters, see Text::ANSI::WideUtil. Current caveats: * Other ANSI codes (non-color codes) are ignored These are codes like for altering cursor positions, etc. * Single-character CSI (control sequence introducer) currently ignored Only "ESC+[" (two-character CSI) is currently parsed. BTW, in ASCII terminals, single-character CSI is 0x9b. In UTF-8 terminals, it is "0xc2, 0x9b" (2 bytes). * Private-mode- and trailing-intermediate character currently not parsed * Only color reset code \e[0m is recognized For simplicity, currently multiple SGR parameters inside a single ANSI color code is not parsed. This means that color reset code like "\e[1;0m" or "\e[31;47;0m" is not recognized, only "\e[0m" is. I believe this should not be a problem with most real-world text out there. CONTRIBUTOR Steven Haryanto (on PC) FUNCTIONS ta_add_color_resets(@text) => LIST Make sure that a color reset command (add "\e[0m") to the end of each element and a replay of all the color codes from the previous element, from the last color reset) to the start of the next element, and so on. Return the new list. This makes each element safe to be combined with other array of text into a single line, e.g. in a multicolumn/tabular layout. An example: Without color resets: my @col1 = split /\n/, "\e[31mred\nmerah\e[0m"; my @col2 = split /\n/, "\e[32mgreen\e[1m\nhijau tebal\e[0m"; printf "%s | %s\n", $col1[0], $col2[0]; printf "%s | %s\n", $col1[1], $col2[1]; the printed output: \e[31mred | \e[32mgreen merah\e[0m | \e[1mhijau tebal\e[0m The "merah" text on the second line will become green because of the effect of the last color command printed ("\e[32m"). However, with ta_add_color_resets(): my @col1 = ta_add_color_resets(split /\n/, "\e[31mred\nmerah\e[0m"); my @col2 = ta_add_color_resets(split /\n/, "\e[32mgreen\e[1m\nhijau tebal\e[0m"); printf "%s | %s\n", $col1[0], $col2[0]; printf "%s | %s\n", $col1[1], $col2[1]; the printed output ("<...>") marks the code added by ta_add_color_resets(): \e[31mred<\e[0m> | \e[32mgreen\e[1m<\e[0m> <\e[31m>merah\e[0m | <\e[32m\e[1m>hijau tebal\e[0m All the cells are printed with the intended colors. ta_detect($text) => BOOL Return true if $text contains ANSI color codes, false otherwise. ta_extract_codes($text) => STR This is the opposite of "ta_strip()", return only the ANSI codes in $text. ta_highlight($text, $needle, $color) => STR Highlight the first occurrence of $needle in $text with <$color>, taking care not to mess up existing colors. $needle can be a string or a Regexp object. Implementation note: to not mess up colors, we save up all color codes from the last reset ("\e[0m") before inserting the highlight color + highlight text. Then we issue "\e[0m" and the saved up color code to return back to the color state before the highlight is inserted. This is the same technique as described in "ta_add_color_resets()". ta_highlight_all($text, $needle, $color) => STR Like "ta_highlight()", but highlight all occurrences instead of only the first. ta_length($text) => INT Count the number of characters in $text, while ignoring ANSI color codes. Equivalent to "length(ta_strip($text))". See also: "ta_mbswidth()" in Text::ANSI::WideUtil. ta_length_height($text) => [INT, INT] Like "ta_length()", but also gives height (number of lines). For example, "ta_length_height("foobar\nb\n")" gives "[6, 3]". See also: "ta_mbswidth_height()" in Text::ANSI::WideUtil. ta_pad($text, $width[, $which[, $padchar[, $truncate]]]) => STR Return $text padded with $padchar to $width columns. $which is either "r" or "right" for padding on the right (the default if not specified), "l" or "left" for padding on the right, or "c" or "center" or "centre" for left+right padding to center the text. $padchar is whitespace if not specified. It should be string having the width of 1 column. Does *not* handle multiline text; you can split text by "/\r?\n/" yourself. See also: "ta_mbpad()" in Text::ANSI::WideUtil. ta_split_codes($text) => LIST Split $text to a list containing alternating ANSI color codes and text. ANSI color codes are always on the second element, fourth, and so on. Example: ta_split_codes(""); # => () ta_split_codes("a"); # => ("a") ta_split_codes("a\e[31m"); # => ("a", "\e[31m") ta_split_codes("\e[31ma"); # => ("", "\e[31m", "a") ta_split_codes("\e[31ma\e[0m"); # => ("", "\e[31m", "a", "\e[0m") ta_split_codes("\e[31ma\e[0mb"); # => ("", "\e[31m", "a", "\e[0m", "b") ta_split_codes("\e[31m\e[0mb"); # => ("", "\e[31m\e[0m", "b") so you can do something like: my @parts = ta_split_codes($text); while (my ($text, $ansicode) = splice(@parts, 0, 2)) { ... } ta_split_codes_single($text) => LIST Like "ta_split_codes()" but each ANSI color code is split separately, instead of grouped together. This routine is currently used internally e.g. for "ta_wrap()" and "ta_highlight()" to trace color reset/replay codes. ta_strip($text) => STR Strip ANSI color codes from $text, returning the stripped text. ta_substr($text, $pos, $len[ , $replacement ]) => STR A bit like Perl's "substr()". If $replacement is not specified, will return the substring. If $replacement is specified, will return $text with the substring replaced by $replacement. See also: "ta_mbsubstr()" in Text::ANSI::WideUtil. ta_trunc($text, $width) => STR Truncate $text to $width columns while still including all the ANSI color codes. This ensures that truncated text still reset colors, etc. Does *not* handle multiline text; you can split text by "/\r?\n/" yourself. See also: "ta_mbtrunc()" in Text::ANSI::WideUtil. ta_wrap($text, $width, \%opts) => STR Like Text::WideChar::Util's "wrap()" except handles ANSI color codes. Perform color reset at the end of each line and a color replay at the start of subsequent line so the text is safe for combining in a multicolumn/tabular layout. Options: * flindent => STR First line indent. Currently must not contain ANSI color codes or wide characters. * slindent => STR Subsequent line indent. Currently must not contain ANSI color codes or wide characters. * tab_width => INT (default: 8) * pad => BOOL (default: 0) If set to true, will pad each line to $width. This is convenient if you need the lines padded, saves calls to ta_pad(). * return_stats => BOOL (default: 0) If set to true, then instead of returning the wrapped string, function will return "[$wrapped, $stats]" where $stats is a hash containing some information like "max_word_width", "min_word_width". * keep_trailing_space => BOOL (default: 0) If set to true, then trailing space that separates words will be kept at the end of wrapped lines. This option is useful if you want to rejoin the lines later. Without this option set to true, wrapping this line at width=4 (quotes shown): "some long line" will result in: "some" "long" "line" While if this option is set to true, the result will be: "some " "long " "line" Performance: ~500/s on my Core i5 1.7GHz laptop for a ~1KB of text (with zero to moderate amount of color codes). See also: "ta_mbwrap()" in Text::ANSI::WideUtil. FAQ Why split functionalities of wide character and color support into multiple modules/distributions? Performance (see numbers in the function description), dependency (Unicode::GCString is used for wide character support), and overhead (loading Unicode::GCString). How do I highlight a string case-insensitively? You can currently use a regex for the $needle and use the "i" modifier. Example: use Term::ANSIColor; ta_highlight($text, qr/\b(foo)\b/i, color("bold red")); HOMEPAGE Please visit the project's homepage at . SOURCE Source repository is at . BUGS Please report any bugs or feature requests on the bugtracker website When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. SEE ALSO String::Pad provides padding function for strings that do not contain ASCII escape codes nor wide characters. Text::NonWideChar::Util provides some other functions for strings that do not contain ASCII escape codes nor wide characters. Text::WideChar::Util provides utilities for strings that do not contain ANSI escape codes *but* contain wide characters. Text::ANSI::WideUtil provides utilities for strings that contain ANSI escape codes *and* wide characters. AUTHOR perlancar COPYRIGHT AND LICENSE This software is copyright (c) 2021, 2016, 2015, 2014, 2013 by perlancar . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Text-ANSI-Util-0.233/Changes0000644000175000017500000001252014104005531013030 0ustar u1u10.233 2021-08-08 Released-By: PERLANCAR; Urgency: medium - [bugfix][function ta_wrap] Fix handling of flindent & slindent options (GH#1). 0.232 2021-04-14 Released-By: PERLANCAR; Urgency: low - No functional changes. - [doc] Add FAQ item about the reason for splitting functionalities over modules/distributions. 0.231 2021-01-23 Released-By: PERLANCAR; Urgency: medium - ta_wrap, ta_mbwrap: Add option keep_trailing_space. - [doc] Mention some related modules. 0.230 2019-04-22 Released-By: PERLANCAR - No functional changes. - Spelling [RT#129226]. 0.22 2016-03-11 Released-By: PERLANCAR - [Removed features] Remove Text::ANSI::NonWideUtil (ugly name), but remove wide-character supporting functions (ta_mb*()) in Text::ANSI::Util. 0.21 2015-08-20 Released-By: PERLANCAR - No functional changes. - [doc] Add some description and mention Text::ANSI::WideUtil. 0.20 2015-08-20 Released-By: PERLANCAR - Split Text::ANSI::WideUtil to its own dist. - Re-pass tests [RT#106535]. 0.19 2015-08-13 Released-By: PERLANCAR - Adjust abstract and documentation. We now only deal with ANSI color codes (SGR, \e[...m) and ignore non-color ANSI escape codes. - [Bugfix] Add pruning of ANSI color codes so multiple replacement using ta_substr() will not become increasingly slower due to proliferation of unpruned color codes (due to ta_trunc()). - [Bugfix] Make ta_wrap work without Text::WideChar::Util (previously, ta_wrap always uses regex patterns from Text::WideChar::Util despite $is_mb is 0). - [Bugfix] Fix regex pattern for ANSI color codes (previous one was too broad). - Add (currently minimal) bench devscript. 0.18 2015-08-12 Released-By: PERLANCAR - Add functions: ta_substr, ta_mbsubstr. 0.17 2015-08-12 Released-By: PERLANCAR - Make Text::WideChar::Util an optional prereq. - Also provide Text::ANSI::WideUtil and the leaner Text::ANSI::NonWideUtil (the latter doesn't load Unicode modules, use this if you do not have Unicode/wide characters in your text). 0.16 2015-01-03 Released-By: PERLANCAR - No functional changes. - Rebuild (Generate TODO.md). 0.15 2014-02-11 Released-By: SHARYANTO [BUG FIXES] - ta_mbwrap(): Fix small wrapping bug (whitespace before line-broken CJK word was omitted). 0.14 2014-02-11 Released-By: SHARYANTO [BUG FIXES] - ta_mbwrap(): Long CJK words were not line-broken exhaustively. 0.13 2014-02-11 Released-By: SHARYANTO - ta_mbwrap(): Add support for wrapping Chinese/CJK text. 0.12 2013-10-29 Released-By: SHARYANTO - No functional changes. Rebuild to resolve 'nested encoding' problem causing MetaCPAN to fail to index the dist (thanks Shantanu Bhadoria). 0.11 2013-09-10 Released-By: SHARYANTO - Replace Text::CharWidth's mbswidth() with Text::WideChar::Util's mbswidth(), which in turn uses Unicode::GCString. It's about 2.5x slower but more proper and builds on my Windows installation. 0.10 2013-05-17 Released-By: SHARYANTO [ENHANCEMENTS] - Add return_stats option to ta_{mb,}wrap. 0.09 2013-05-17 Released-By: SHARYANTO [BUG FIXES] - ta_{mb,}wrap(): truncated long word did not retain color at the last line. 0.08 2013-04-19 Released-By: SHARYANTO [ENHANCEMENTS] - Add functions: ta_extract_codes, ta_add_color_resets, ta_length_height. - ta_highlight{,all}: $needle can now be a Regexp. - ta_{,mb}wrap: Reimplement, now behavior similar to Text::WideChar::Util's {,mb}wrap(). [INCOMPATIBLE CHANGES] - ta_highlight{,_all}: Remove argument $ci, now use qr/foo/i as $needle for case-insensitive highlighting. 0.07 2013-04-10 Released-By: SHARYANTO - Add functions: ta_split_codes_single, ta_highlight, ta_highlight_all. 0.06 2013-04-09 Released-By: SHARYANTO [BUG FIXES] - ta_mbtrunc(): Use mbtrunc() which is the proper method, instead of substr(). - ta_mbpad(): Since ta_mbtrunc() might generate text with width of ($width-1) or less, depending on the width of the truncated wide character, we need to pad the truncated text to go to $width. 0.05 2013-04-09 Released-By: SHARYANTO [INCOMPATIBLE CHANGES] - ta_{,mb}pad() now does not handle multiline text (the implementation was incorrect after all, "" should've been padded to "xxx" and "a\n" should've been padded to "axx\nxxx"). You can now split multiline text by yourself as you see fit. 0.04 2013-04-08 Released-By: SHARYANTO [BUG FIXES] - ta_{,mb}wrap(): Handles multiple paragraph, fix bug where last word of text is sometimes removed, do not remove terminating newline. 0.03 2013-04-06 Released-By: SHARYANTO [ENHANCEMENTS] - Add functions: ta_split_codes, ta_{,mb}trunc, ta_{,mb}pad. 0.02 2013-03-20 Released-By: SHARYANTO - Fix failing CT reports by skipping tests on systems without Chinese locale support. 0.01 2013-03-13 Released-By: SHARYANTO - First release. Text-ANSI-Util-0.233/MANIFEST0000644000175000017500000000047714104005531012676 0ustar u1u1# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.017. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Text/ANSI/BaseUtil.pm lib/Text/ANSI/Util.pm t/#01-basic.t# t/00-compile.t t/01-latin.t t/author-critic.t t/author-pod-coverage.t t/author-pod-syntax.t weaver.ini