# REPL I/O in a Pkg instead of \`readline()\`?

**URL:** https://discourse.julialang.org/t/repl-i-o-in-a-pkg-instead-of-readline/46554
**Category:** New to Julia
**Created:** [September 13, 2020, 5:01pm UTC](https://discourse.julialang.org/t/repl-i-o-in-a-pkg-instead-of-readline/46554 "2020-09-13T17:01:20Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)
#### Post date: [September 13, 2020, 5:01pm UTC](https://discourse.julialang.org/t/repl-i-o-in-a-pkg-instead-of-readline/46554/1 "2020-09-13T17:01:20Z")

</div>

Hi everyone,

Working on a package to give interactive tutorials for new Julia users. Hit a stumbling block that I’m not convinced has a _good_ answer. Basically here’s what I want to happen:

```nohighlight
Hi juliatutor user type `println("hello world")` and hit the return key.
> println("hello wurld")
hello wurld
Sorry that's not the solution we asked for try again.
> println("hello world")
hello world
Good job! Let's move on to the next task.

```

So far I was able to mimic this behaviour with the `readline()` function. But there are serious downsides to using that function when compared to a typical REPL input! For example, hitting the arrow keys in a readline displays some character annotation for the keypress and doesn’t move the cursor (eek)

```nohighlight
julia> readline()
^[[D^[[D^[[D^[[C^[[C^[[C

```

This would frustrate a new user and not provide anything like the REPL experience they would get by closing the package. Full REPL incorporation isn’t needed, but being able to get something closer than `readline()` offers would be awesome.

The current code for this can be found here:  
[https://github.com/caseykneale/JuliaTutor.jl/blob/dd1a8bb618a3c91bc8b8e525f16990eddc7fd54a/src/Prompts.jl#L36](https://github.com/caseykneale/JuliaTutor.jl/blob/dd1a8bb618a3c91bc8b8e525f16990eddc7fd54a/src/Prompts.jl#L36)

I’ve looked into REPLMaker.jl at the suggestion of others and the base code for REPL’s itself but quick attempts at getting what I wanted didn’t work out. Does anyone have any good ideas for this? Or is this hopeless for now?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [September 13, 2020, 5:22pm UTC](https://discourse.julialang.org/t/repl-i-o-in-a-pkg-instead-of-readline/46554/2 "2020-09-13T17:22:45Z")

</div>

> [@anon92994695](#):
>
> I’ve looked into REPLMaker.jl at the suggestion of others and the base code for REPL’s itself but quick attempts at getting what I wanted didn’t work out.

That’s pretty much what you are going to have to use though. For inspiration, you can look at Pkg, Debugger for custom REPL modes.

---

<div class="post-metadata">

### Author: ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)
#### Post date: [September 13, 2020, 5:27pm UTC](https://discourse.julialang.org/t/repl-i-o-in-a-pkg-instead-of-readline/46554/3 "2020-09-13T17:27:26Z")

</div>

I for some reason didn’t think to look at Pkg, or Debugger. Great idea. I’ll take a peek at those sometime soon and give this another try. I know how I’d go about doing this in another Language but in Julia it’s a little more nuanced so following the road more traveled should help a lot.

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [September 13, 2020, 5:56pm UTC](https://discourse.julialang.org/t/repl-i-o-in-a-pkg-instead-of-readline/46554/4 "2020-09-13T17:56:27Z")

</div>

This is one of the goals of Pluto notebooks. Have you seen the homeworks for our course, for example?

[https://computationalthinking.mit.edu/Fall20/hw1/](https://computationalthinking.mit.edu/Fall20/hw1/)

---

<div class="post-metadata">

### Author: ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)
#### Post date: [September 13, 2020, 8:15pm UTC](https://discourse.julialang.org/t/repl-i-o-in-a-pkg-instead-of-readline/46554/5 "2020-09-13T20:15:55Z")

</div>

I didn’t know that! No I haven’t seen your homeworks, but I did star the repo. Figured I’d jump in once you all get past the image stuff I already know :).

Have you ever heard of Swirl, it’s an R package? [CRAN - Package swirl](https://cran.r-project.org/web/packages/swirl/index.html)

Swirl taught someone who I thought would take months to write code to do so in a matter of a week or so. Albeit dangerously. So I wanted to make something like that in Julia.

The code I have for evaluating answers came from @travigd who was also working on automated course work evaluation code as well.

If you (MIT/JuliaComputing people) all are already working on this I can just trashcan the project. Nothing like this existed when I started it otherwise I wouldn’t have bothered.

Will you by any chance be open-sourcing how you make the notebooks?

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [September 13, 2020, 8:50pm UTC](https://discourse.julialang.org/t/repl-i-o-in-a-pkg-instead-of-readline/46554/6 "2020-09-13T20:50:01Z")

</div>

I haven’t heard of Swirl.  
It certainly doesn’t hurt to have multiple projects.  
Probably some people prefer using the REPL.

Everything is contained in the notebooks themselves (or in Pluto).
