Common Patterns¶
Enable / Disable¶
A program may want to disable progress bars based on a configuration setting as well as if output redirection occurs.
import sys
import enlighten
# Example configuration object
config = {'stream': sys.stdout,
'useCounter': False}
enableCounter = config['useCounter'] and stream.isatty()
manager = enlighten.Manager(stream=config['stream'], enabled=enableCounter)
The get_manager()
function slightly simplifies this
import enlighten
# Example configuration object
config = {'stream': None, # Defaults to sys.stdout
'useCounter': False}
manager = enlighten.get_manager(stream=config['stream'], enabled=config['useCounter'])