The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

ansiprintf - ANSI terminal sequence aware printf command

SYNOPSIS

ansiprintf format args ...

VERSION

Version 2.06

DESCRIPTION

This command is a simple wrapper command for Text::ANSI::Printf library. According to the format given in the first argument, it formats and outputs the remaining arguments.

Even if the string given as an argument contains ANSI terminal sequences, the formatting is done based on the visible width on the screen.

For example, next command

    printf '|%-5s|%-5s|%-5s|\n' Red Green Blue

will print

    |Red  |Green|Blue |

and

    ansiprintf '|%-5s|%-5s|%-5s|\n' \
        $'\e[31mRed\e[m' $'\e[32mGreen\e[m' $'\e[34mBlue\e[m'

will produce same result with colored arguments.

You can give colored arguments with ansiecho(1) command:

    ansiprintf '|%-5s|%-5s|%-5s|\n' $(ansiecho -cR Red -cG Green -cB Blue)

but this can be done with just ansiecho(1):

    ansiecho -f '|%-5s|%-5s|%-5s|' -cR Red -cG Green -cB Blue

In addition to handling ANSI terminal sequences, ansisprintf has the following features.

WIDE and COMBINING CHARACTERS

Asian wide characters are formatted according to the width displayed on the screen. Combining characters in other languages are also handled correctly.

UNICODE CHARACTERS

You can give Unicode character in parameter strings by its name ("\N{ALARM CLOCK}") or code ("\N{U+23F0}").

ARGUMENT REORDERING

You can specify the argument by position specifier like %2$s %1ds. Width, precision, vector string parameter also take position specifier.

This command supports all other features provided by the Perl interpreter. See "sprintf" in perlfunc or `perldoc -f sprintf` for more information.

SEE ALSO

App::ansiecho

Text::ANSI::Printf

printf(1)

AUTHOR

Kazumasa Utashiro

LICENSE

Copyright © 2023- Kazumasa Utashiro.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.