# Why are the colours in errorshow.jl hardcoded?

**URL:** https://discourse.julialang.org/t/why-are-the-colours-in-errorshow-jl-hardcoded/92013
**Category:** General Usage
**Created:** [December 22, 2022, 5:10pm UTC](https://discourse.julialang.org/t/why-are-the-colours-in-errorshow-jl-hardcoded/92013 "2022-12-22T17:10:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Euhan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/euhan/32/36548_2.png) [@Euhan](https://discourse.julialang.org/u/Euhan)
#### Post date: [December 22, 2022, 5:10pm UTC](https://discourse.julialang.org/t/why-are-the-colours-in-errorshow-jl-hardcoded/92013/1 "2022-12-22T17:10:49Z")

</div>

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:

```julia
    # 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:

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

```

Is this the intended, canonical solution to this problem?

---

<div class="post-metadata">

### Author: ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)
#### Post date: [December 22, 2022, 7:30pm UTC](https://discourse.julialang.org/t/why-are-the-colours-in-errorshow-jl-hardcoded/92013/2 "2022-12-22T19:30:15Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![FedeClaudi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fedeclaudi/32/33490_2.png) [@FedeClaudi](https://discourse.julialang.org/u/FedeClaudi)
#### Post date: [December 24, 2022, 6:02pm UTC](https://discourse.julialang.org/t/why-are-the-colours-in-errorshow-jl-hardcoded/92013/3 "2022-12-24T18:02:38Z")

</div>

Perhap’s [Term.jl](https://fedeclaudi.github.io/Term.jl/dev/) can help here:

it style’s error messages and you can choose the [Theme](https://fedeclaudi.github.io/Term.jl/dev/basics/colors_and_theme/#ThemeDocs) to change the colors.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/8/38ce9ec04b35524af4abf62acdd6cff5fe6e383a.png)

---

<div class="post-metadata">

### Author: ![Euhan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/euhan/32/36548_2.png) [@Euhan](https://discourse.julialang.org/u/Euhan)
#### Post date: [January 6, 2023, 1:55am UTC](https://discourse.julialang.org/t/why-are-the-colours-in-errorshow-jl-hardcoded/92013/4 "2023-01-06T01:55:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [January 6, 2023, 6:01am UTC](https://discourse.julialang.org/t/why-are-the-colours-in-errorshow-jl-hardcoded/92013/5 "2023-01-06T06:01:24Z")

</div>

> <https://github.com/JuliaLang/julia/issues/41435>
>
> As suggested here: https://github.com/JuliaLang/julia/pull/41423#issuecomment-87…2208265 it would be good to support theming Julia's colors. There's also https://github.com/JuliaLang/julia/issues/41295 but I think that may overcomplexify things. Without @staticfloat's input, I'm not entirely clear on how using Preferences in Julia would work, whereas I have a pretty clear idea about how adding a config file to theme Julia's colors would work: Instead of hardcoding colors, if Julia is run in color mode, it would look in a file called \`~/.julia/config/colors.toml\` that maps uses of colors as keys to some kind of color description as values. Here are some questions:
> 
> 1. What are the color keys? Presumably descriptions of how we use colors.
> 2. What are the color values? \`#123abc\` strings? ANSI color names? Either?
> 3. Do we need anything else in the file or is it just this map?
> 
> I think for usability we'd probably also want to have changes to this file take effect immediately, so we'd want to remember the inode, size, mtime and ctime and if any of them changes, reload the file. We also want to take care that if we're not using color the file never needs to be looked at.
