From 34e9225db0d61dbcf306ad2eb2901824f0259109 2022-02-25 10:36:37 From: Matthias Bussonnier Date: 2022-02-25 10:36:37 Subject: [PATCH] Merge pull request #13501 from ltrujello/fix_vi_cursor Fixes #13472 by restoring user's terminal cursor after exiting IPython --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 95cb7c7..782ba4c 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -3702,6 +3702,10 @@ class InteractiveShell(SingletonConfigurable): pass del self.tempdirs + # Restore user's cursor + if hasattr(self, "editing_mode") and self.editing_mode == "vi": + sys.stdout.write("\x1b[0 q") + sys.stdout.flush() def cleanup(self): self.restore_sys_module_state() diff --git a/IPython/terminal/shortcuts.py b/IPython/terminal/shortcuts.py index 274f9b2..b53e5b4 100644 --- a/IPython/terminal/shortcuts.py +++ b/IPython/terminal/shortcuts.py @@ -338,12 +338,7 @@ def create_ipython_shortcuts(shell): shape = {InputMode.NAVIGATION: 2, InputMode.REPLACE: 4}.get(mode, 6) cursor = "\x1b[{} q".format(shape) - if hasattr(sys.stdout, "_cli"): - write = sys.stdout._cli.output.write_raw - else: - write = sys.stdout.write - - write(cursor) + sys.stdout.write(cursor) sys.stdout.flush() self._input_mode = mode