From c030907bd8d38d4194ebc9f6f47f283d1e58a844 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 29 Jun 2020 03:53:21 -0400 Subject: [PATCH] Support 'with' statement. --- progressbar/progressbar.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/progressbar/progressbar.py b/progressbar/progressbar.py index 3baf530..a3becc3 100644 --- a/progressbar/progressbar.py +++ b/progressbar/progressbar.py @@ -164,6 +164,12 @@ def __next__(self): # an iterator. next = __next__ + def __enter__(self): + self.start() + return self + + def __exit__(self, type, value, traceback): + self.finish() def _env_size(self): """Tries to find the term_width from the environment."""