Manage the printing and in-place updating of a line of characters. Note that if the string is longer than a line, then in-place updating may not work (it will print a new line at each refresh).
(file)
| 437 | |
| 438 | @staticmethod |
| 439 | def status_printer(file): |
| 440 | """ |
| 441 | Manage the printing and in-place updating of a line of characters. |
| 442 | Note that if the string is longer than a line, then in-place |
| 443 | updating may not work (it will print a new line at each refresh). |
| 444 | """ |
| 445 | fp = file |
| 446 | fp_flush = getattr(fp, 'flush', lambda: None) # pragma: no cover |
| 447 | if fp in (sys.stderr, sys.stdout): |
| 448 | getattr(sys.stderr, 'flush', lambda: None)() |
| 449 | getattr(sys.stdout, 'flush', lambda: None)() |
| 450 | |
| 451 | def fp_write(s): |
| 452 | fp.write(str(s)) |
| 453 | fp_flush() |
| 454 | |
| 455 | last_len = [0] |
| 456 | |
| 457 | def print_status(s): |
| 458 | len_s = disp_len(s) |
| 459 | fp_write('\r' + s + (' ' * max(last_len[0] - len_s, 0))) |
| 460 | last_len[0] = len_s |
| 461 | |
| 462 | return print_status |
| 463 | |
| 464 | @staticmethod |
| 465 | def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it', |