How do I erase printed characters in a console application(Linux)?

前端 未结 6 1609
慢半拍i
慢半拍i 2020-12-14 19:54

I am creating a small console app that needs a progress bar. Something like...

Conversion: 175/348 Seconds   |==========          |  50%

My

6条回答
  •  鱼传尺愫
    2020-12-14 20:34

    \r did the trick.

    For future reference, \b does not work in PHP in Linux. I was curious - so I did a couple of experiments in other languages as well(I did this in Linux - I don't know if the result will be the same in Windows/Mac)..

    \b Works in...

    • Perl
    • Ruby
    • Tcl - with code puts -nonewline "Hello\b"

    \b Doesn't work in

    • PHP - the code print "Hello\b"; prints out Hello\b
    • Python - code print "Hello\b" prints out Hello . Same result with print "Hello\b",

提交回复
热议问题