-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add handling for cow files with custom colors #2
Comments
On further testing, I don't like many of these ideas. Maybe a silhouette will be the best option, or just ignoring it |
Hi, thanks for pointing this out. Unfortunately, In saying that, if you really want to fill in the colours, and the import re
from cowsay import read_dot_cow, cowsay
ANSI_PATTERN = re.compile(
r'(?:^|\n)(\$.+) = "(.+)";'
)
with open("batman.cow", "r") as f:
replacements = {
k: v.replace("\\e", "\x1b")
for k, v in ANSI_PATTERN.findall(f.read())
}
f.seek(0)
cow = read_dot_cow(f, replacements)
print(cowsay("hello", cowfile=cow)) |
Just following up on this. I just released a new version of python-cowsay that adds a CLI and also handles the colourful cow files you mentioned. These files should now be rendered with colours by default. |
Hello!
First off, thank you for making this library!
Right now, if you use a custom colored cow file (like some of the examples here, the cow will not properly be converted to text.
String output:
cowfile: batman.cow
Theoretically, string substitution could be used to create variables and substitute throughout the file... but at that point, you're almost creating a bash shell in python
My proposed solution is to do a simple check in
read_dot_cow()
. If the line starts with a$
and has an=
sign, it should remove all color formatting from the string (or have an option to leave it in) and add it to another dictionary, similar toESCAPES
, and replace all these variables at the end.The text was updated successfully, but these errors were encountered: