How clear the printed content in terminal and print to the same line?

You can try using ANSI codes (to my understanding, an ancient standard of terminal manipulation), here is a code of a function that overwrites the last line and prints something new

#source: https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences
# a more complete description of the codes used.

function overprint(str)  
    print("\u1b[1F")
    #Moves cursor to beginning of the line n (default 1) lines up   
    print(str)   #prints the new line
   print("\u1b[0K") 
   # clears  part of the line.
   #If n is 0 (or missing), clear from cursor to the end of the line. 
   #If n is 1, clear from cursor to beginning of the line. 
   #If n is 2, clear entire line. 
   #Cursor position does not change. 

    println() #prints a new line, i really don't like this arcane codes
end

#testing
println(1)
println(2)
println(3)
println(4)
println(5)
println("this is the number six")
overprint(7)
println(8)

Output:

1
2
3
4
5
7
8
5 Likes