`<` and `>` keys break MyCLI in vi mode
dbedrenko opened this issue · comments
Version: 1.26.1
Steps to reproduce:
- Use the default config file and set
key_bindings = vi
- Run
mycli
and press<
This is the error I get:
Connecting to socket /var/run/mysqld/mysqld.sock, owned by user mysql
MariaDB 11.0.2
mycli 1.26.1
Home: http://mycli.net
Bug tracker: https://github.com/dbcli/mycli/issues
Thanks to the contributor - orpharion bestheneme
Unhandled exception in event loop:
File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/lib/python3.11/site-packages/prompt_toolkit/input/vt100.py", line 162, in callback_wrapper
callback()
File "/usr/lib/python3.11/site-packages/prompt_toolkit/application/application.py", line 712, in read_from_input_in_context
context.copy().run(read_from_input)
File "/usr/lib/python3.11/site-packages/prompt_toolkit/application/application.py", line 692, in read_from_input
self.key_processor.process_keys()
File "/usr/lib/python3.11/site-packages/prompt_toolkit/key_binding/key_processor.py", line 272, in process_keys
self._process_coroutine.send(key_press)
File "/usr/lib/python3.11/site-packages/prompt_toolkit/key_binding/key_processor.py", line 187, in _process
self._call_handler(matches[-1], key_sequence=buffer[:])
File "/usr/lib/python3.11/site-packages/prompt_toolkit/key_binding/key_processor.py", line 322, in _call_handler
handler.call(event)
File "/usr/lib/python3.11/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 124, in call
result = self.handler(event)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mycli/key_bindings.py", line 96, in _
cursorpos_relative = b.cursor_position / len(b.text)
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
Exception division by zero
Press ENTER to continue...
MariaDB danb@(none):(none)>
Actually in vi insert mode pressing '<' seems to execute some sort of "prettify" library on the input, e.g. if you have this on your prompt with the cursor after having
and press <
:
select * from `Person` where Person.id in (select max(id) from Person group by Email having );
Instead of inserting a <
it says on the status line
" Unprettify failed to parse statement Right-arrow to complete suggestion".
So in summary, I can't insert a <
nor >
.
Hi! I introduced this feature many months ago. But I thought someone else had fixed the issues with vi bindings. Will review. It is simple enough to revert the feature in vi mode.
Thank you, and thank you for such a handy application!
In the mean time I found a workaround: pasting '<' and '>' from clipboard does not trigger the prettify feature.
Indeed the bindings were removed in #1089; it seems we are just overdue for a release.
Ah I see, that's too bad :( I think I will stick with the current version to keep the vi bindings as it's too much of a pain editing input in the other modes. Thanks for looking into it anyway.
Sorry, I meant that the <
issue is fixed and will propagate out if we do a release today.
https://github.com/dbcli/mycli/releases/tag/v1.27.0
1.27.0 is on PyPi now, and includes the primitive fix of just disabling the prettify functionality in vi-mode. Later we should find someone who understand vi bindings well enough to enable it the right way. Sorry this went unreleased for a while.
Works great now! Big thank you!