osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

if STREAM.isatty():


On 31Aug2019 08:57, Cameron Simpson <cs at cskk.id.au> wrote:
>On 30Aug2019 10:25, Michael Torrie <torriem at gmail.com> wrote:
>>On Fri, Aug 30, 2019, 05:02 Hongyi Zhao <hongyi.zhao at gmail.com wrote:
>>>On Fri, 30 Aug 2019 17:53:02 +1000, Chris Angelico wrote:
>>>> (Also, why the sleep? Seems unnecessary.)
>>>
>>>Because without using sleep, the stuff on screen will display very
>>>shortly and then disappear.  Is this not your testing result?
>>
>>No it is not. What kind of terminal are you using?
>
>Note that testing this stuff in a regular terminal will us the \r 
>version. Which leaves the cursor at the left end of the progress 
>display. Where it will be overwritten by your prompt, depending on the 
>shell.
>
>So what he describes is entirely possible on UNIX.

And just further to this. It is more common to write his one-line update 
not as:

  progress_status+'\r'

as he has it, which leaves the cursor at the left ready to overwrite 
things, but as:

  '\r' + progress_status

which backs up to the start of the line, writes the status, and leaves 
the cursor at the end.

The latter has the advantage that any subsequent output (egthe shell 
prompt after the programmke exits) will not overwrite the status string.

Cheers,
Cameron Simpson <cs at cskk.id.au>