What happens in the background when I press `]` and enter the pkg mode?

To install a package, we usually open the REPL and press ] to enter the package mode.

Today I suddenly notice that I can’t find an easy way to imitate this behavior. Because with functions like read and readline, users need to explicitly press Enter. But when we entering the package mode, the prefix changed from julia> to pkg> immediately.

I tried to answer this question by reading the source code of REPL but no luck. Things are very complicated there to me. I would appreciate it very much if anyone can point out how is everything working in the background.

Use the Pkg API directly:


Thanks for your immediate reply!

Sorry that I didn’t make it clear.

In fact I want to write a customized mode. But struggling to figure out how to read user’s input (one character exactly, like ] for package mode, ; for shell mode) without the need to press enter.

The way I wrote the Pkg repl mode was to copy an existing repl mode and then modify it until it did what I wanted. We need a better API but until then, that’s the state of the art.


Look at

1 Like

searching https://pkg.julialang.org/docs/ for REPL also gives https://github.com/MasonProtter/ReplMaker.jl

1 Like


This is exactly what I want!

by the way, if you are interested in reproducing the exact same REPL behavior as in Pkg, I was able to isolate the required code in my VerTeX.jl package, where I have a vtx> REPL prompt:

however, I don’t recommend using this approach unless you absolutely need the same kind of interface, which I needed in this case because VerTeX is also a package manager but for \LaTeX nodes.

for most REPL interfaces, a simpler approach will work, such as also the one in Reduce.jl or the ones based on ReplMaker and so on, the approach of copying the Pkg REPL was only used in VerTeX because I need to build similar package management features into it.