{"html_url": "https://github.com/simonw/sqlite-utils/issues/433#issuecomment-1578840450", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/433", "id": 1578840450, "node_id": "IC_kwDOCGYnMM5eGzGC", "user": {"value": 392720, "label": "jonafato"}, "created_at": "2023-06-06T14:09:04Z", "updated_at": "2023-06-06T14:09:04Z", "author_association": "NONE", "body": "I also ran into this recently. See below for a patch for one possible solution (tested via \"it works on my machine\", but I don't expect that this behavior would vary a whole lot across terminal emulators and shells). Another possible solution might be to subclass click's `ProgressBar` to keep the logic within the original context manager. Happy to send a PR or for this patch to serve as the basis for a fix that someone else authors.\r\n\r\n```patch\r\ndiff --git a/sqlite_utils/utils.py b/sqlite_utils/utils.py\r\nindex 06c1a4c..530a3a3 100644\r\n--- a/sqlite_utils/utils.py\r\n+++ b/sqlite_utils/utils.py\r\n@@ -147,14 +147,23 @@ def decode_base64_values(doc):\r\n \r\n \r\n class UpdateWrapper:\r\n- def __init__(self, wrapped, update):\r\n+ def __init__(self, wrapped, update, render_finish):\r\n self._wrapped = wrapped\r\n self._update = update\r\n+ self._render_finish = render_finish\r\n \r\n def __iter__(self):\r\n- for line in self._wrapped:\r\n- self._update(len(line))\r\n- yield line\r\n+ return self\r\n+\r\n+ def __next__(self):\r\n+ try:\r\n+ line = next(self._wrapped)\r\n+ except StopIteration as e:\r\n+ self._render_finish()\r\n+ raise\r\n+\r\n+ self._update(len(line))\r\n+ return line\r\n \r\n def read(self, size=-1):\r\n data = self._wrapped.read(size)\r\n@@ -178,7 +187,7 @@ def file_progress(file, silent=False, **kwargs):\r\n else:\r\n file_length = os.path.getsize(file.name)\r\n with click.progressbar(length=file_length, **kwargs) as bar:\r\n- yield UpdateWrapper(file, bar.update)\r\n+ yield UpdateWrapper(file, bar.update, bar.render_finish)\r\n \r\n \r\n class Format(enum.Enum):\r\n\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1239034903, "label": "CLI eats my cursor"}, "performed_via_github_app": null}