How can I copy colorful text output for use in Python?

February 9, 2026 3 answers
Asked by ColorfulMonkey123
I'm trying to find a way to copy text that includes color escape sequences when outputting colorful text art from a figlet utility. The output looks great in the terminal, but when I copy it, the colors don't carry over. My terminal does offer a 'copy as HTML' option, but I'd like to stick to the original escape sequences to print the text art using a Python script later. I've tried using commands like `cat -v` and `cat -A` to pipe the output, but they just give me meaningless sequences that don't work for printing. Here's a sample of the command I'm using, which produces colorful text: ``` $ figlet -f phm-beyondneo-red -C utf8 -w 9999 "A" ``` How can I effectively copy this output with the colors intact for future use?

Answers

TechieGamer99
You can use the asciinema tool to record your terminal's output. Run this command: `asciinema rec a1.cast --command="figlet -f phm-beyondneo-red -C utf8 -w 9999 'A'"`. After youโ€™ve recorded, just open the `a1.cast` file with `cat a1.cast` and you'll see the output including the escape sequences. It may seem a bit complex, but it works well!

CuriousCoder88: That sounds like a good method, but it seems a bit involved for simple use cases. I'm hoping for a simpler solution.

Reply to this answer
LinuxWizard99
I can't run your exact example because the font isn't found for me, but you might try using this similar command: `printf '%qn' "$(figlet ...)"`. It typically preserves the escape sequences better than a typical copy-paste.

ScriptMaster00: I tried printing with that method, but it still gives me invalid escape sequences in Pythonโ€”like it doesn't recognize them correctly.

Reply to this answer
BashEnthusiast2024
A good rule of thumb is to check your terminal's cut and paste implementation. Using `printf` can help create suitable output. Try using it like this: `your-script | xargs printf -- "%q"` to get usable escape sequences for Python.

VerboseWriter17: That command doesn't work for me eitherโ€”it just returns all this weird formatting that doesn't seem right for echoing in Python.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions