Advertisement
HasteBin0

Python Simple Status Indicator

Jun 11th, 2020 (edited)
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. def simple_status():
  2.     def simple_status_internal():
  3.         while True:
  4.             tmp = ' ' * int((yield))
  5.             while True:
  6.                 new = str(new_raw := (yield))
  7.                 if new_raw is None:
  8.                     print(' ' * len(tmp), end = '\r', flush = True)
  9.                     break
  10.                 print('\r', new.rjust(len(tmp), ' '), sep = '', end = '', flush = True)
  11.                 tmp = new
  12.  
  13.     next(f := simple_status_internal())
  14.     return lambda msg: f.send(msg)
  15.  
  16. out = simple_status()
  17. for _ in 'ab':
  18.     out(6)  # spaces
  19.     for i in range(1_000_000): out(i)
  20.     for i in range(1_000_000, -1, -1): out(i)
  21.     out(None)
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement