Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you clear or overwrite a line of text in DrRacket?

Tags:

racket

I would like to display text and then overwrite it (for simple progress bars, etc.). The usual trick of displaying a carriage return ("\r") works fine when running Racket in the terminal in Linux and Windows, but in DrRacket and GRacket the carriage return does not seem to move the cursor to the beginning of the line.

With this code as an example:

(for ([x 5])
  (display "\r")
  (display x)    
  (flush-output) ; The result is the same with or without this line
  (sleep 0.1))

Running in the terminal results in a counter that overwrites itself; at the end only 4 is displayed in the terminal.

Running in DrRacket results in the numbers displaying and not being overwritten:

0
1
2
3
4

Is there a way to overwrite a line of text in the interactions window of DrRacket?

like image 896
ohspite Avatar asked Oct 18 '22 02:10

ohspite


1 Answers

For an authoritative answer on this, you'll want to hear from Robby Findler on the racket users mailing list, (see https://lists.racket-lang.org/).

I'm about 85% certain that the interactions window doesn't do this: that is, allow you to overwrite already displayed text. If you wanted to do something like this, you'd probably want to create your own text window using the graphical toolbox. That way, you could alter the text in the window in any way you wanted.

like image 168
John Clements Avatar answered Dec 19 '22 21:12

John Clements