Printing/Debugging¶
A Concourse resource is supposed to print output (such as versions and metadata) to stdout, and all debugging messages to stderr. The ConcourseResource class automatically redirects stdout to stderr when running its methods, meaning that all printed output from you (and from your dependencies) automatically ends up in stderr.
Colour¶
The Concourse web UI will interpret ANSI colour codes,
and so a handful of rudimentary functions for formatting with colour are include in
concoursetools.colour.
Tip
There are plenty of more mature libraries for printing coloured output, such as termcolor and Rich. Concourse Tools specifically has no external dependencies, and so these must be actively installed and managed by a user.
- concoursetools.colour.colourise(string, colour)[source]¶
Convert a string into a string which will be coloured on print.
This enables coloured output within an f-string or similar. It is not recommended for colouring complete strings, as it is far less efficient than the other functions.
- Parameters:
string (
str) – The string to be colourised.colour (
str) – The ANSI colour escape code for the required colour.
- Example:
>>> print(f"Hello {colourise('world', colour=Colour.RED)}")
- Return type:
- concoursetools.colour.colour_print(*values, colour=_NoPrint(), bold=False, underline=False, **print_kwargs)[source]¶
Print something in colour.
This function behaves exactly like
print(), just with more functionality:
- concoursetools.colour.print_in_colour(colour, bold=False, underline=False)[source]¶
Print anything in colour within a context manager.
This is especially useful for colourising output from other external functions which you cannot control.
Available Colours¶
All colour arguments are ANSI colour escape codes, but a number of common codes are available as attributes of the Colour class: