terminalcolorsjuliaxfce

Running Julia and getting colors to output on (unix-like) command line


I am getting started with Julia, and am watching this video, and at the time I linked to, the presenter runs the command

palette = distinguishable_colors(100)

Now if I run that in my terminal (xfce4-terminal), I just get output that looks

 RGB{N0f8}(0.471,0.482,0.231)
 RGB{N0f8}(0.714,0.976,0.851)
 RGB{N0f8}(0.855,0.0,0.247)
 RGB{N0f8}(0.18,0.129,0.141)
 RGB{N0f8}(0.0,0.345,0.082)
 RGB{N0f8}(1.0,0.557,0.114)
 RGB{N0f8}(0.4,0.455,0.694)
 RGB{N0f8}(0.0,0.804,0.678)
 RGB{N0f8}(0.0,0.498,0.388)
 RGB{N0f8}(0.6,0.435,0.239)

Is there a way to get it to output actually colors on the terminal (like in the video)? Is this something that has to be updated in a separate config (and what exactly?), or something that needs to be tuned in Julia?


Solution

  • Sure you can just use the Crayons package. This package is using Ints for representation of colors and the API of Colors.jl is rather verbose here (unless you want directly access pallette object fields which would be not elegant).

    using Color, Crayons
    
    palette = distinguishable_colors(8);
    
    crs = [Crayon(foreground = reinterpret.((red(palette[i]), green(palette[i]),blue(palette[i]))) ) for i in 1:8];
    
    println.(crs, string.("This is line ",1:8));
    

    enter image description here

    Note that the first line ha black color so it is not visible, however you can always add something like background=:white to the Crayon constructor.

    enter image description here