{"html_url": "https://github.com/simonw/sqlite-utils/issues/433#issuecomment-1793274350", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/433", "id": 1793274350, "node_id": "IC_kwDOCGYnMM5q4zHu", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-11-04T00:46:30Z", "updated_at": "2023-11-04T00:46:30Z", "author_association": "OWNER", "body": "And a GIF of the fix after applying:\r\n- #598\r\n\r\n![cursor-fix](https://github.com/simonw/sqlite-utils/assets/9599/35829aec-c9ac-4925-a8e6-ffe7c2ab0d96)\r\n", "reactions": "{\"total_count\": 1, \"+1\": 1, \"-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} {"html_url": "https://github.com/simonw/sqlite-utils/issues/433#issuecomment-1793273968", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/433", "id": 1793273968, "node_id": "IC_kwDOCGYnMM5q4zBw", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-11-04T00:45:19Z", "updated_at": "2023-11-04T00:45:19Z", "author_association": "OWNER", "body": "Here's an animated GIF that demonstrates the bug:\r\n\r\n![cursor-bug](https://github.com/simonw/sqlite-utils/assets/9599/18e54b38-a466-4384-9162-114eb01526a2)\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} {"html_url": "https://github.com/simonw/sqlite-utils/issues/433#issuecomment-1747231893", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/433", "id": 1747231893, "node_id": "IC_kwDOCGYnMM5oJKSV", "user": {"value": 62745, "label": "spookylukey"}, "created_at": "2023-10-04T16:15:09Z", "updated_at": "2023-10-04T16:28:21Z", "author_association": "CONTRIBUTOR", "body": "I confirm the bug, as above, and that @jonafato 's patch fixes it for me. However, it's not the right fix. The problem is that ProgressBar is being used in the wrong way. This also results in two lines being printed instead of one, like this:\r\n\r\n```\r\n [#######-----------------------------] 20%\r\n [####################################] 100%% \r\n```\r\nThe bug is reproducible for me in any terminal, including Gnome Terminal and Guake, and VSCode. With VSCode I can use this launch.json to reproduce it:\r\n\r\n```json\r\n\r\n{\r\n \"version\": \"0.2.0\",\r\n \"configurations\": [\r\n {\r\n \"name\": \"Python: Module\",\r\n \"type\": \"python\",\r\n \"request\": \"launch\",\r\n \"module\": \"sqlite_utils\",\r\n \"justMyCode\": false,\r\n \"args\": [\"insert\", \"test.db\", \"test\", \"--csv\", \"tests/sniff/example1.csv\"]\r\n }\r\n ]\r\n}\r\n```\r\n\r\n[edit - deleted my analysis of why the current code is wrong, which was confused and confusing]", "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} {"html_url": "https://github.com/simonw/sqlite-utils/issues/433#issuecomment-1640826795", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/433", "id": 1640826795, "node_id": "IC_kwDOCGYnMM5hzQer", "user": {"value": 76528036, "label": "J450n-4-W"}, "created_at": "2023-07-18T19:08:50Z", "updated_at": "2023-07-18T19:08:50Z", "author_association": "NONE", "body": "Came here to report this, but instead I'll confirm the issue across two terminal emulators (Gnome Terminal and Alacritty) on Pop_OS! 22.04 (currently based on Ubuntu/Gnome). Also messes up the formatting of the terminal. Can also confirm that reset fixes it until the next sqlite-utils command. ", "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} {"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} {"html_url": "https://github.com/simonw/sqlite-utils/issues/433#issuecomment-1444474487", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/433", "id": 1444474487, "node_id": "IC_kwDOCGYnMM5WGO53", "user": {"value": 167893, "label": "mcarpenter"}, "created_at": "2023-02-24T20:57:43Z", "updated_at": "2023-02-24T22:22:18Z", "author_association": "CONTRIBUTOR", "body": "I think I see what is happening here, although I haven't quite work out a fix yet. Usually:\r\n\r\n* `click.progressbar.render_progress()` renders the cursor invisible on each invocation (update of the bar)\r\n* When the progress bar goes out of scope, the `__exit()__` method is invoked, which calls `render_finish()` to make the cursor re-appear.\r\n\r\n(See terminal escape sequences `BEFORE_BAR` and `AFTER_BAR` in click).\r\n\r\nHowever the sqlite-utils `utils.file_progress` context manager wraps `click.progressbar` and yields an instance of a helper class:\r\n\r\n``` python\r\n@contextlib.contextmanager \r\ndef file_progress(file, silent=False, **kwargs):\r\n ...\r\n with click.progressbar(length=file_length, **kwargs) as bar:\r\n yield UpdateWrapper(file, bar.update) \r\n```\r\n\r\nThe yielded `UpdateWrapper` goes out of scope quickly and `click.progressbar.__exit__()` is called. The cursor is made un-invisible. Hoewever `bar` is still live and so when the caller iterates on the yielded wrapper this invokes the bar's update method, calling `render_progress()`, each time printing the \"make cursor invisible\" escape code. The `progressbar.__exit__` function is not called again, so the cursor doesn't re-appear.\r\n\r\n", "reactions": "{\"total_count\": 1, \"+1\": 1, \"-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} {"html_url": "https://github.com/simonw/sqlite-utils/issues/433#issuecomment-1416486796", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/433", "id": 1416486796, "node_id": "IC_kwDOCGYnMM5Ubd-M", "user": {"value": 16236421, "label": "alecstein"}, "created_at": "2023-02-03T22:32:10Z", "updated_at": "2023-02-03T22:32:10Z", "author_association": "NONE", "body": "Came here to say that I also have this issue.", "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} {"html_url": "https://github.com/simonw/sqlite-utils/issues/433#issuecomment-1252898131", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/433", "id": 1252898131, "node_id": "IC_kwDOCGYnMM5KrbVT", "user": {"value": 7908073, "label": "chapmanjacobd"}, "created_at": "2022-09-20T20:51:21Z", "updated_at": "2022-09-20T20:56:07Z", "author_association": "CONTRIBUTOR", "body": "When I run `reset` it fixes my terminal. I suspect it is related to the progress bar\r\n\r\nhttps://linux.die.net/man/1/reset\r\n\r\n```\r\n950 1s /m/d/03_Downloads \ud83d\udc11 echo $TERM\r\nxterm-kitty\r\n\u2593\u2591\u2592\u2591 /m/d/03_Downloads \ud83c\udf0f kitty -v\r\nkitty 0.26.2 created by Kovid Goyal\r\n$ sqlite-utils insert test.db facility facility-boundary-us-all.csv --csv\r\nblah blah blah (no offense)\r\n$ \r\n$ reset\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} {"html_url": "https://github.com/simonw/sqlite-utils/issues/433#issuecomment-1155749696", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/433", "id": 1155749696, "node_id": "IC_kwDOCGYnMM5E41dA", "user": {"value": 9599, "label": "simonw"}, "created_at": "2022-06-14T21:57:05Z", "updated_at": "2022-06-14T21:57:05Z", "author_association": "OWNER", "body": "Marking this as help wanted because I can't figure out how to replicate it!", "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} {"html_url": "https://github.com/simonw/sqlite-utils/issues/433#issuecomment-1139484453", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/433", "id": 1139484453, "node_id": "IC_kwDOCGYnMM5D6ycl", "user": {"value": 4068, "label": "frafra"}, "created_at": "2022-05-27T10:20:08Z", "updated_at": "2022-05-27T10:20:08Z", "author_association": "NONE", "body": "I can confirm. This only happens with sqlite-utils. I am using gnome-terminal with bash.", "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}