Search code examples
pythoncommand-linecross-platform

Easy cross-platform python way of colouring text in the command line/shell


Bascially, I want an easy(ish), cross-platform way of colouring text in the command line/shell.

I would really like this to not involve importing a module, but because cross-platform support is pretty complicated, I know it will probably have to.

I don't need it to be too elaborate though, just a few basic colours will do.


Solution

  • Writing ANSI excape sequences doesn't require anything fancy and should be fairly easy.

    Here is a basic exaple that show how it can be done manually.*

    Or you could also have a look of libraries like termcolor or colorama for reference.

    *edit: just seen that this example isn't really fully functional. to make it work 33[ has to be replaced with \033[