Why are the colours in errorshow.jl hardcoded?

After having struggled with debugging on command-line (rather that jupyter that I had been using before), I realised that the trace of stack frames provides references to files and lines in the output. I had not noticed because the text was the same off-black as my terminal emulator.

I saw some tips about setting environment variables to get the right colour. I would have preferred to do it in my startup.jl, but alright. I try to set JULIA_STACKFRAME_FUNCTION_COLOR and JULIA_STACKFRAME_LINEINFO_COLOR to absolutely no avail.

When I looked in errorshow.jl, I discovered these lines:

    # filepath
    pathparts = splitpath(file)
    folderparts = pathparts[1:end-1]
    if !isempty(folderparts)
        printstyled(io, joinpath(folderparts...) * (Sys.iswindows() ? "\\" : "/"), color = :light_black)
    end

    # filename, separator, line
    # use escape codes for formatting, printstyled can't do underlined and color
    # codes are bright black (90) and underlined (4)
    printstyled(io, pathparts[end], ":", line; color = :light_black, underline = true)

    # inlined
    printstyled(io, inlined ? " [inlined]" : "", color = :light_black)

I.e. The colours are hardcoded. In view of this, why do the environment variables and functions such as Base.stackframe_function_color even exist?

My current workaround is this addition to my startup.jl:

Base.text_colors[Symbol("light_black")]="\e[1;38;2;192;224;255m"

Is this the intended, canonical solution to this problem?

I think the canonical solution is to make sure that your terminal displays all 16 colours. It seems odd that themes sometimes assign two to the same output… iTerm has a slider to impose a minimum contrast, over-riding the theme.

There was talk of making the error colours configurable, but nobody has got around to it.

1 Like

Perhap’s Term.jl can help here:

it style’s error messages and you can choose the Theme to change the colors.

Ottimo suggerimento! It’s not actually a solution to the problem in general, so I won’t mark it as such, but certainly a work-around that I will try out. It seems to come with other advantages as well.