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

**URL:** <https://discourse.julialang.org/t/what-happens-in-the-background-when-i-press-and-enter-the-pkg-mode/22829>\
**Category:** New to Julia\
**Created:** [April 6, 2019, 6:38am UTC](https://discourse.julialang.org/t/what-happens-in-the-background-when-i-press-and-enter-the-pkg-mode/22829 "2019-04-06T06:38:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![findmyway](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/findmyway/32/4946_2.png) [@findmyway](https://discourse.julialang.org/u/findmyway)\
**Post date:** [April 6, 2019, 6:38am UTC](https://discourse.julialang.org/t/what-happens-in-the-background-when-i-press-and-enter-the-pkg-mode/22829/1 "2019-04-06T06:38:39Z")

</div>

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`](https://github.com/JuliaLang/julia/tree/master/stdlib/REPL/src) 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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 6, 2019, 6:48am UTC](https://discourse.julialang.org/t/what-happens-in-the-background-when-i-press-and-enter-the-pkg-mode/22829/2 "2019-04-06T06:48:00Z")

</div>

Use the `Pkg` API directly:

[https://julialang.github.io/Pkg.jl/dev/api/](https://julialang.github.io/Pkg.jl/dev/api/)

---

<div class="post-metadata">

**Author:** ![findmyway](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/findmyway/32/4946_2.png) [@findmyway](https://discourse.julialang.org/u/findmyway)\
**Post date:** [April 6, 2019, 6:58am UTC](https://discourse.julialang.org/t/what-happens-in-the-background-when-i-press-and-enter-the-pkg-mode/22829/3 "2019-04-06T06:58:19Z")

</div>

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 `.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [April 6, 2019, 7:02am UTC](https://discourse.julialang.org/t/what-happens-in-the-background-when-i-press-and-enter-the-pkg-mode/22829/4 "2019-04-06T07:02:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 6, 2019, 7:16am UTC](https://discourse.julialang.org/t/what-happens-in-the-background-when-i-press-and-enter-the-pkg-mode/22829/5 "2019-04-06T07:16:00Z")

</div>

Look at

> **[GitHub - KristofferC/OhMyREPL.jl: Syntax highlighting and other enhancements...](https://github.com/KristofferC/OhMyREPL.jl)**
>
> Syntax highlighting and other enhancements for the Julia REPL - GitHub - KristofferC/OhMyREPL.jl: Syntax highlighting and other enhancements for the Julia REPL

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [April 6, 2019, 8:03am UTC](https://discourse.julialang.org/t/what-happens-in-the-background-when-i-press-and-enter-the-pkg-mode/22829/6 "2019-04-06T08:03:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![findmyway](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/findmyway/32/4946_2.png) [@findmyway](https://discourse.julialang.org/u/findmyway)\
**Post date:** [April 6, 2019, 2:17pm UTC](https://discourse.julialang.org/t/what-happens-in-the-background-when-i-press-and-enter-the-pkg-mode/22829/7 "2019-04-06T14:17:17Z")

</div>

Thanks!

This is exactly what I want!

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [April 6, 2019, 2:30pm UTC](https://discourse.julialang.org/t/what-happens-in-the-background-when-i-press-and-enter-the-pkg-mode/22829/8 "2019-04-06T14:30:49Z")

</div>

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](https://github.com/chakravala/VerTeX.jl) package, where I have a `vtx>` REPL prompt:

> <https://github.com/chakravala/VerTeX.jl/blob/master/src/repl.jl>

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](https://github.com/chakravala/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.
