# Proper way(s) to write to the output port in a console application?

**URL:** <https://racket.discourse.group/t/proper-way-s-to-write-to-the-output-port-in-a-console-application/3537>\
**Category:** Questions & Answers\
**Tags:** cli\
**Created:** [February 3, 2025, 11:07am UTC](https://racket.discourse.group/t/proper-way-s-to-write-to-the-output-port-in-a-console-application/3537 "2025-02-03T11:07:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bakgatviooldoos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bakgatviooldoos/32/1381_2.png) [@bakgatviooldoos](https://racket.discourse.group/u/bakgatviooldoos)\
**Post date:** [February 3, 2025, 11:07am UTC](https://racket.discourse.group/t/proper-way-s-to-write-to-the-output-port-in-a-console-application/3537/1 "2025-02-03T11:07:52Z")

</div>

Hi, Racket Discourse.

I am busy fiddling around with a command-line script, and I am wondering what I am doing wrong with the "dynamic" display to the terminal's output. I am running on a `kali linux` instance, for what it is worth.

Below is an example of the code for and running of the animated text:

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/0/0a8168d4f2c87817c154e20d38745af2ace4d6f6.png)

Which is required and started from the main script.

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/6/672b9b56b826c0e4c66726e8549f937b8c2e5018.png)

![screen-capture-01](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/3/306881cf433c84e4614bac9a0999032118751a28.gif)

This works fine and has the intended effect. Now I would like to add the number of seconds and minutes the particular command has been busy, but the "backspace" character-method from the above does not seem to work all the way.

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/8/8b714735a0298618fbfc0fca5b217d3b71327eb7.png)

Notice in the output how the leftover `01`s remain there after the `okay` when waiting ends:

![screen-capture-02](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/9/9d372c42c45e08bedaab73c88a7b4a1488bd787f.gif)

I can imagine that the `#\backspace`s might not be doing what I expect, since text can be tricky to say the least.

How do you usually do dynamic text animations in Racket cli applications?

---

<div class="post-metadata">

**Author:** ![shhyou](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@shhyou](https://racket.discourse.group/u/shhyou)\
**Post date:** [February 3, 2025, 12:22pm UTC](https://racket.discourse.group/t/proper-way-s-to-write-to-the-output-port-in-a-console-application/3537/2 "2025-02-03T12:22:00Z")

</div>

`#\backspace`, or the ASCII `"\b"` character, moves the cursor one step leftward but does not otherwise have more effects. Therefore to erase the old content, the code would need to print spaces:

```bash
$ printf "abcdefg\b\b\b\bO\n"
abcOefg
$ printf "abcdefg\b\b\b\b \b\b\b\bO\n"
abcO   

```

---

<div class="post-metadata">

**Author:** ![bakgatviooldoos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bakgatviooldoos/32/1381_2.png) [@bakgatviooldoos](https://racket.discourse.group/u/bakgatviooldoos)\
**Post date:** [February 3, 2025, 12:33pm UTC](https://racket.discourse.group/t/proper-way-s-to-write-to-the-output-port-in-a-console-application/3537/3 "2025-02-03T12:33:15Z")

</div>

Ah, that makes perfect sense. TIL.

This does the trick.

```scheme
(define erase (make-string 18 #\backspace))
(define space (make-string 18 #\space))
(write-string erase)
(write-string space)
(write-string erase)

```

Thank you!

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [February 3, 2025, 5:22pm UTC](https://racket.discourse.group/t/proper-way-s-to-write-to-the-output-port-in-a-console-application/3537/4 "2025-02-03T17:22:38Z")

</div>

PS in the future it helps to share textual codeblocks rather than screenshots.
