diff --git a/README.md b/README.md index c7d4006..35b085f 100644 --- a/README.md +++ b/README.md @@ -39,32 +39,45 @@ For example, this code produces the output like: - | Red | Green | Blue | +
+

+

However, if the arguments are colored by ANSI sequence, printf("| %-5s | %-5s | %-5s |\n", - "\e[31mRed\e[m", "\e[32mGreen\e[m", "\e[34mBlue\e[m"); + "\e[31mRed\e[m", "\e[32;3mGreen\e[m", "\e[34;3;4mBlue\e[m"); this code produces undesirable result: - | Red | Green | Blue | +
+

+

-This is still better because it is readable, but if the result is -shorter than the original string, for example, "%.3s", the result will -be disastrous. +This is still better because the output is readable, but if the result +is shorter than the original string, for example, "%3.3s", the result +will be disastrous. `ansi_printf` can be used to properly format colored text. use Text::ANSI::Printf 'ansi_printf'; ansi_printf("| %-5s | %-5s | %-5s |\n", - "\e[31mRed\e[m", "\e[32;3mGreen\e[m", "\e[34;3;4mBlue\e[m"); + "\e[31mRed\e[m", "\e[32;3mGreen\e[m", "\e[34;3;4mBlue\e[m"); + +
+

+

It does not matter if the result is shorter than the original text. Next code produces `[R] [G] [B]` in proper color. + use Text::ANSI::Printf 'ansi_printf'; ansi_printf("[%.1s] [%.1s] [%.1s]\n", - "\e[31mRed\e[m", "\e[32;3mGreen\e[m", "\e[34;3;4mBlue\e[m"); + "\e[31mRed\e[m", "\e[32;3mGreen\e[m", "\e[34;3;4mBlue\e[m"); + +
+

+

# RELATED TOOLS @@ -77,7 +90,6 @@ follows. use Text::ANSI::Printf 'ansi_printf'; use Term::ANSIColor::Concise 'ansi_color'; - ansi_printf("| %-5s | %-5s | %-5s |\n", ansi_color("R", "Red", "GI", "Green", "BIU", "Blue")); diff --git a/images/bad.png b/images/bad.png new file mode 100644 index 0000000..89ef329 Binary files /dev/null and b/images/bad.png differ diff --git a/images/good.png b/images/good.png new file mode 100644 index 0000000..6076bf4 Binary files /dev/null and b/images/good.png differ diff --git a/images/plain.png b/images/plain.png new file mode 100644 index 0000000..5bda58a Binary files /dev/null and b/images/plain.png differ diff --git a/images/shorten.png b/images/shorten.png new file mode 100644 index 0000000..4b0bd19 Binary files /dev/null and b/images/shorten.png differ diff --git a/lib/Text/ANSI/Printf.pm b/lib/Text/ANSI/Printf.pm index d1965cf..d481d48 100644 --- a/lib/Text/ANSI/Printf.pm +++ b/lib/Text/ANSI/Printf.pm @@ -82,32 +82,71 @@ For example, this code produces the output like: +=begin :text + | Red | Green | Blue | +=end :text + +=begin html + +

+ +=end html + However, if the arguments are colored by ANSI sequence, printf("| %-5s | %-5s | %-5s |\n", - "\e[31mRed\e[m", "\e[32mGreen\e[m", "\e[34mBlue\e[m"); + "\e[31mRed\e[m", "\e[32;3mGreen\e[m", "\e[34;3;4mBlue\e[m"); this code produces undesirable result: +=begin :text + | Red | Green | Blue | -This is still better because it is readable, but if the result is -shorter than the original string, for example, "%.3s", the result will -be disastrous. +=end :text + +=begin html + +

+ +=end html + +This is still better because the output is readable, but if the result +is shorter than the original string, for example, "%3.3s", the result +will be disastrous. C can be used to properly format colored text. use Text::ANSI::Printf 'ansi_printf'; ansi_printf("| %-5s | %-5s | %-5s |\n", - "\e[31mRed\e[m", "\e[32;3mGreen\e[m", "\e[34;3;4mBlue\e[m"); + "\e[31mRed\e[m", "\e[32;3mGreen\e[m", "\e[34;3;4mBlue\e[m"); + +=begin html + +

+ +=end html It does not matter if the result is shorter than the original text. Next code produces C<[R] [G] [B]> in proper color. + use Text::ANSI::Printf 'ansi_printf'; ansi_printf("[%.1s] [%.1s] [%.1s]\n", - "\e[31mRed\e[m", "\e[32;3mGreen\e[m", "\e[34;3;4mBlue\e[m"); + "\e[31mRed\e[m", "\e[32;3mGreen\e[m", "\e[34;3;4mBlue\e[m"); + +=begin html + +

+ +=end html + +=begin :text + + [R] [G] [B] + +=end :text =head1 RELATED TOOLS @@ -120,7 +159,6 @@ follows. use Text::ANSI::Printf 'ansi_printf'; use Term::ANSIColor::Concise 'ansi_color'; - ansi_printf("| %-5s | %-5s | %-5s |\n", ansi_color("R", "Red", "GI", "Green", "BIU", "Blue"));