print_with_color

print_with_color(color::Symbol, [io], strings...)

Print strings in a color specified as a symbol, for example :red or :blue.

Examples

  1. Print text in red color:

    julia> print_with_color(:red, "Hello, world!")
  2. Print multiple strings with different colors:

    julia> print_with_color(:red, :blue, "Red text", "Blue text")
  3. Specify output stream (io) for colored printing:
    julia> io = open("output.txt", "w")
    julia> print_with_color(:green, io, "This text will be written to a file in green color")

Common mistake example:

julia> print_with_color("red", "Hello, world!")
ERROR: MethodError: no method matching print_with_color(::String, ::String)

In this example, the color argument is passed as a string instead of a symbol. Make sure to provide the color as a symbol (:red, :blue, etc.) to avoid this error.

See Also

:@printf, :@sprintf, display, displayable, dump, info, isprint, print, println, print_escaped, print_joined, print_shortest, print_unescaped, print_with_color, pushdisplay, redisplay, show, showall, showcompact, sprint, versioninfo,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: