erkin / ponysay

Pony rewrite of cowsay.
GNU General Public License v3.0
1.19k stars 81 forks source link

ponysay -l should not print bold names when piped to another command (Ansible) #272

Open clonedagain opened 6 years ago

clonedagain commented 6 years ago

Currently, ponysay prints some names in bold when called with -l, +l, -L, -A, +A.

It becomes a problem when trying to post-process the output, for example build a list of ponies to choose from.

For example, I like to link ponysay instead of cowsay, and enjoy it when using Ansible, but that restricts me to the non-bold pony names. That's because Ansible calls "cowsay -l" to get list of cows and filter using a whitelist, and it can't remove the escape codes : https://github.com/ansible/ansible/blob/e9b0a4ccb42854329b33b06624379c6122b67bd7/lib/ansible/utils/display.py#L99

loxaxs commented 5 years ago

In https://gist.github.com/loxaxs/5a318bc347fb7c77c2757cc7011ae468, I had to use a hack to avoid the problem.

I piped the output through sed 's/\x1b\[[0-9;]*m//g' to remove the escape sequences. If you need to remove the name alias between parenthesis (as I did), you might want to use sed 's/\x1b\[[0-9;]*m//g;s/(.*)//g' instead.