# Easy way to update text in terminal (instead of printing more text)?

**URL:** https://discourse.julialang.org/t/easy-way-to-update-text-in-terminal-instead-of-printing-more-text/81818
**Category:** General Usage
**Tags:** cli
**Created:** [May 27, 2022, 10:04pm UTC](https://discourse.julialang.org/t/easy-way-to-update-text-in-terminal-instead-of-printing-more-text/81818 "2022-05-27T22:04:21Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)
#### Post date: [May 27, 2022, 10:04pm UTC](https://discourse.julialang.org/t/easy-way-to-update-text-in-terminal-instead-of-printing-more-text/81818/1 "2022-05-27T22:04:21Z")

</div>

I would like to show progress of a `for` loop, updating the text like like “1/100”, “2/200”, until “100/100”. The rest of the program, before or after the loop, would print text in the usual way without changing old text. How should I do this?

---

<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: [May 27, 2022, 10:08pm UTC](https://discourse.julialang.org/t/easy-way-to-update-text-in-terminal-instead-of-printing-more-text/81818/2 "2022-05-27T22:08:49Z")

</div>

See [GitHub - timholy/ProgressMeter.jl: Progress meter for long-running computations](https://github.com/timholy/ProgressMeter.jl)

---

<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: [May 27, 2022, 10:12pm UTC](https://discourse.julialang.org/t/easy-way-to-update-text-in-terminal-instead-of-printing-more-text/81818/3 "2022-05-27T22:12:43Z")

</div>

In particular, this is done with [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code), as in [this example](https://github.com/timholy/ProgressMeter.jl/blob/83e619faed2780ab5d6929777c8f6151e3b88c5e/src/ProgressMeter.jl#L614-L625)

---

<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: [May 27, 2022, 11:06pm UTC](https://discourse.julialang.org/t/easy-way-to-update-text-in-terminal-instead-of-printing-more-text/81818/4 "2022-05-27T23:06:14Z")

</div>

[Linking here](https://discourse.julialang.org/t/update-variable-in-logged-message-without-printing-a-new-line/32755/3) one example of ANSI escape sequence suggested by Steve.

And sample code here below for easier reference:

```julia
for n in 1:100
    print("Iteration number $n/100\u001b[1000D")
    sleep(0.002) # to simulate code waiting time
end

```

---

<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: [May 27, 2022, 11:12pm UTC](https://discourse.julialang.org/t/easy-way-to-update-text-in-terminal-instead-of-printing-more-text/81818/5 "2022-05-27T23:12:33Z")

</div>

There is also the simple `print("\r")` solution:

```julia
for i in 1:100
    print("\rIteration: $(i)/100")
    sleep(0.002) # to simulate code waiting time
end

```

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [March 2, 2024, 4:35pm UTC](https://discourse.julialang.org/t/easy-way-to-update-text-in-terminal-instead-of-printing-more-text/81818/6 "2024-03-02T16:35:48Z")

</div>

> [@rafael.guerra](#):
>
> ```julia
> for i in 1:100
> print("\rIteration: $(i)/100")
> sleep(0.002) # to simulate code waiting time
> end
> 
> ```

Unfortunately this seems not to work in Jupyter notebooks in vscode, it just prints a bunch of lines.

 ![Screenshot 2024-03-02 at 17.36.13](https://global.discourse-cdn.com/julialang/original/3X/7/9/79a61cee24add5fb69bb4a48acadc80d2f37dc34.png)

Any suggestions?

---

<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 2, 2024, 7:20pm UTC](https://discourse.julialang.org/t/easy-way-to-update-text-in-terminal-instead-of-printing-more-text/81818/7 "2024-03-02T19:20:56Z")

</div>

> [@e3c6](#):
>
> Unfortunately this seems not to work in Jupyter notebooks in vscode

Works for me:

![image](https://global.discourse-cdn.com/julialang/original/3X/6/6/66943631f110ff834caeb7abbdbfd5aa717fd5e4.png)

(vscode 1.87.0 on Mac.) vscode had an issue with ANSI escapes at one point, but it was supposedly fixed years ago ([vscode#112178](https://github.com/microsoft/vscode/issues/112178)).

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [March 2, 2024, 8:50pm UTC](https://discourse.julialang.org/t/easy-way-to-update-text-in-terminal-instead-of-printing-more-text/81818/8 "2024-03-02T20:50:48Z")

</div>

That’s strange. For me it definitely prints new lines. Note that there are still open issues, which I think might be related to this, e.g.: [Which terminal control/escape sequences need to be supported? · Issue #271 · timholy/ProgressMeter.jl · GitHub](https://github.com/timholy/ProgressMeter.jl/issues/271), and [Notebook output must support more ANSI sequences · Issue #118833 · microsoft/vscode · GitHub](https://github.com/microsoft/vscode/issues/118833).

I have no clue what setting might be make things different for me. I also have vscode 1.87 on Mac.
