REPL color questions: variable names, seeing them, and setting RGB values

The REPL’s package mode prompt is too dark, and I want to change it.

I’ve found the REPL documentation, and it shows how to set variables using startup.jl, and I now have a few questions that go beyond changing the prompt color.

What is the variable name for the package prompt?

The name probably starts with ‘repl.’, so how do I get a list of all variables starting with ‘repl.’?

The documentation says “the available color keys can be seen by typing Base.text in help mode”, but it doesn’t show the colors, it just shows a short list of color names. Besides, assigning these names to variables using startup.jl, how can I see the colors associated with the names using the REPL?

I will almost certainly want to adjust the individual RGB values for the package mode prompt. How does one do that?

Have a look at

Thanks oheil. I saw that last night, and I rescanned its documentation just now. While I can imagine I might be able to use this, and I don’t get the feeling it deals with the package mode prompt, I don’t want to get bogged down making a new theme right now. I’m more interested in things like discovering variable names and setting RGB values for something specific.

For example:

help?> Base.text_colors
  Dictionary of color codes for the terminal.

  Available colors are: :normal, :default, :bold, :black, :blink, :blue, :cyan, :green, :hidden, :light_black,
  :light_blue, :light_cyan, :light_green, :light_magenta, :light_red, :light_white, :light_yellow, :magenta, :nothing,
  :red, :reverse, :underline, :white, or :yellow as well as the integers 0 to 255 inclusive.

  The color :default will print text in the default color while the color :normal will print text with all text
  properties (like boldness) reset. Printing with the color :nothing will print the string without modifications.

julia> println(Base.text_colors[:light_red] * "light_red")
light_red

Of course you can’t see the color here, but in your REPL it should appear “light_red” in a light_red color :slight_smile:

The package prompt is probably defined in Pkg. Now you say

so do you want me to tell you how to change the pkg prompt or do you want me to help you finding out on your own?
(Currently I don’t know if it’s easy to change it and how it works, I have just an idea).

Thank you again oheil. I’m looking forward to repeating your example when I finish my work day. That’s exactly the kind of thing I want to try in the REPL.

Well, I want to learn both. So go ahead and share your thoughts. Telling me the answer won’t keep me from working on how to go about finding it. Your answer will only help.

You can’t change the Pkg prompt ‘pkg>’ it’s hard coded in
…\share\julia\stdlib\v1.8\Pkg\src\REPLMode\REPLMode.jl:

function promptf()
    ...
    return "$(prefix)pkg> "
end

But changing it in the file can be done of course.

I once proposed changing the default palette, but the issue was closed. There isn’t strictly any default palette, or at least it differs by terminal. In my Linux Mint the background was grey and I don’t understand it at all, why would any programmer want that?! I changed to a non-default palette (which might be default for others) and everything is fine now.

Are you on Windows and what terminal do you use?

Windows and PowerShell (for now). I can’t cut and paste into my Julia session (grr) ; PowerShell and I may have a short relationship. Fortunately oheil’s printf example was short enough to type.

There’s no accounting for taste. Seriously, it’s almost impossible to know, or anticipate, all expectations or situations.

I don’t fault anyone for making a choice for the Pkg prompt that I wouldn’t make, but I expect to be able to change it to improve visibility on my system.

oheil points out I can mod the code on my system, which I’ll mess with once I find it. :slight_smile:

This was the subject of an issue in 2019 - BLue colour on black bacground - almost invisible · Issue #788 · JuliaLang/Pkg.jl · GitHub - As yet, no-one has volunteered to make a PR. Perhaps Pkg mode could be added to the modes described in Customizing-Colors.

To be honest, it would be easier to redefine the terminal’s idea of “blue”:

although I’m not familiar with the abilities of your terminal program in this area.

Yes, changing the terminal’s idea of “blue” is easier, but Microsoft chose to be incompatible. They still don’t provide this ability in PowerShell. PowerShell’s “experimental terminal settings” link mentions VT codes, which seem to be what Base.text_colors contains: “[e[38;5;86m” for example.

If I understand correctly, because colors are chosen by VT codes, I won’t be able to remap the VT code to RGB values unless I can do it in the terminal settings. That leaves modifying my local REPLMode.jl, or using a different terminal. Neither choice sounds attractive.

Please let me know if I’ve read the situation wrong.

For the record, VS Code’s Julia extension doesn’t have this problem, but I am avoiding it for other issues, hence my thought to use the Julia REPL to get a clean editor + terminal like experience.

The following Code snippet (paste it into REPL) lets you control the Pkg prompt without changing the original source file. There are still some issues with it, as you can see at the commented code lines, but at this point I let it up to you if you want to follow this path. Actually I am not sure if this is a viable path.

import Pkg.REPLMode.promptf, Pkg.REPLMode.OFFLINE_MODE, Pkg.REPLMode.prev_project_timestamp, Pkg.REPLMode.prev_prefix, Pkg.REPLMode.prev_project_file, Pkg.REPLMode.projname
import Pkg.Types

function promptf()
    #global prev_project_timestamp, prev_prefix, prev_project_file
    project_file = try
        Types.find_project_file()
    catch
        nothing
    end
    prefix = ""
    if project_file !== nothing
        if prev_project_file == project_file && prev_project_timestamp == mtime(project_file)
            prefix = prev_prefix
        else
            project_name = projname(project_file)
            if project_name !== nothing
                prefix = "($(project_name)) "
                #prev_prefix = prefix
                #prev_project_timestamp = mtime(project_file)
                #prev_project_file = project_file
            end
        end
    end
    if OFFLINE_MODE[]
        prefix = "$(prefix)[offline] "
    end
    #return "$(prefix)pkg> "
    return "$(prefix) "*Base.text_colors[:light_red]*"MyOwnPkgPrompt> "
end

Thank you, oheil. I tried the code out, and the result isn’t quite what I thought it would be from my first look over. There’s the red text I expected, but there’s also blue and some extra space. That’s perfectly fine. I’ll try and figure it all out, learn from it, and then maybe use it. I appreciate your help very much.

2 Likes

Thanks again for all of your earlier comments and suggestion.

I found a solution this morning that works well and was easy to install: Windows Terminal.

Windows Terminal is a new, modern, feature-rich, productive terminal application for command-line users. It includes many of the features most frequently requested by the Windows command-line community including support for tabs, rich text, globalization, configurability, theming & styling, and more.

Upon installing Terminal and running Julia inside it, the REPL is clearly rendered, and the fonts, including the package mode fonts, are easily readable.