# Glitch with readline() in VSCode?

**URL:** <https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550>\
**Category:** General Usage\
**Tags:** vscode, input-output, interactivity\
**Created:** [March 4, 2023, 6:08pm UTC](https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550 "2023-03-04T18:08:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maddy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maddy/32/210658_2.png) [@Maddy](https://discourse.julialang.org/u/Maddy)\
**Post date:** [March 4, 2023, 6:08pm UTC](https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550/1 "2023-03-04T18:08:41Z")

</div>

![Screenshot (157)](https://global.discourse-cdn.com/julialang/original/3X/c/7/c740c481d18c99f867043d3fc0d706095c459fd5.png)  
 ![Screenshot (158)](https://global.discourse-cdn.com/julialang/original/3X/1/c/1c9dc4a43c3c3fd783d98df175e0b2365caea07c.png)

(Ignore the code I wrote… the glitch is about the REPL)  
The first time I input something for readline(), nothing happens. I have to enter my input again. And after the code is done running, a weird `input` not defined pops up  
This seems like some known bug. Has this been fixed yet? Any good workarounds?

Also, why does VSCode stick that 0 at the end of my print statement in the REPL? That is not supposed to be there…

---

<div class="post-metadata">

**Author:** ![Maddy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maddy/32/210658_2.png) [@Maddy](https://discourse.julialang.org/u/Maddy)\
**Post date:** [March 4, 2023, 6:19pm UTC](https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550/2 "2023-03-04T18:19:00Z")

</div>

Whoah! I ran the code in REPL. The ‘0’ still seems to be there at the end of print statement. I thought it was a vscode glitch. what’s happening?

---

<div class="post-metadata">

**Author:** ![Maddy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maddy/32/210658_2.png) [@Maddy](https://discourse.julialang.org/u/Maddy)\
**Post date:** [March 4, 2023, 6:22pm UTC](https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550/3 "2023-03-04T18:22:51Z")

</div>

![Screenshot (159)](https://global.discourse-cdn.com/julialang/original/3X/4/9/49bcc6afb066c26327c6b089676bdf1601b67c8b.png)

Is anyone seeing this!? There are 0’s in such a simple code too… WHATS HAPPENING?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 4, 2023, 6:52pm UTC](https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550/4 "2023-03-04T18:52:34Z")

</div>

> [@Maddy](#):
>
> Is anyone seeing this!? There are 0’s in such a simple code too… WHATS HAPPENING?

This should give you a clue:

```julia
julia> println("10\r9")
90

```

`\r` does not clear the line, it only moves the cursor.

PS. In general, please don’t post screenshots. Post quoted code: [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![Maddy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maddy/32/210658_2.png) [@Maddy](https://discourse.julialang.org/u/Maddy)\
**Post date:** [March 5, 2023, 8:34am UTC](https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550/5 "2023-03-05T08:34:43Z")

</div>

My bad, sorry. But how do you clear the current line entirely then?

---

<div class="post-metadata">

**Author:** ![\_bernhard](https://avatars.discourse-cdn.com/v4/letter/_/bc79bd/32.png) [@\_bernhard](https://discourse.julialang.org/u/_bernhard)\
**Post date:** [March 5, 2023, 7:18pm UTC](https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550/6 "2023-03-05T19:18:04Z")

</div>

You could do something along the lines of

```julia
println("\r ")

```

i.e. overwriting the prvious text with spaces.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [March 5, 2023, 9:04pm UTC](https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550/7 "2023-03-05T21:04:35Z")

</div>

For the simple countdown example, you could use Printf:

```julia
using Printf
for n in 15:-1:1
    @printf("\r%3i",n)
    sleep(0.1)
end

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [March 6, 2023, 8:58am UTC](https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550/8 "2023-03-06T08:58:57Z")

</div>

Also relevant, depending on how you run your code:

> <https://github.com/julia-vscode/julia-vscode/issues/785>
>
> There seems to be an issue with the new terminal communication and reading stdin…. Executing the file
> \`\`\`julia
> for n in 1:5
> println(n)
> readline()
> end
> \`\`\`
> through vscode will drop back to the REPL prompt after the first iteration. Loading the same file with include() works as expected.
> 
> Version: 0.12.0-beta.2
> OS: Windows 10

---

<div class="post-metadata">

**Author:** ![Maddy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maddy/32/210658_2.png) [@Maddy](https://discourse.julialang.org/u/Maddy)\
**Post date:** [March 6, 2023, 1:08pm UTC](https://discourse.julialang.org/t/glitch-with-readline-in-vscode/95550/9 "2023-03-06T13:08:41Z")

</div>

```julia
using REPL.Terminals
function clear_line()
    terminal = Terminals.TTYTerminal("", stdin, stdout, stderr)
    Terminals.clear_line(terminal)
end

```

I came up with this code with a little research. Don’t really know how REPL.Terminals works… but this code works pretty smoothly for me, although the above suggestions work just as fine! Thank you all for them!
