dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.42k stars 661 forks source link

Make Alt-Enter context-sensitive, depending on multi-line or single-line mode #924

Closed rolandwalker closed 3 years ago

rolandwalker commented 3 years ago

Description

xref #748

Make Alt-Enter context-sensitive, inserting a linefeed in single-line mode, but dispatching the command in multi-line mode.

In short, Alt-Enter mostly inverts the expected action of Enter.

Motivation: I can't find another way to dispatch a command like

SELECT * from TABLE WHERE \e

in multi-line mode.

Also, make Control-j unconditionally insert linefeed in Emacs mode. Rationale: preserves an easy "unconditional insert" feature. Happy to remove this part, which may be debatable. Edit: and, the Control-j binding may break the assumptions of the test suite.

Note that it was always possible to unconditionally insert linefeeds via quoted-insert (Emacs mode Control-q Control-j, Vi mode Control-v Control-j).

Checklist

rolandwalker commented 3 years ago

I just noticed _multiline_exception() which is another way that ending a line with \e could/should be supported.

amjith commented 3 years ago

Do we just need to kick off a new test run to verify that it passes or are we still waiting on changes in this PR?

rolandwalker commented 3 years ago

From our Slack conversation I thought you had an idea about how to change the PR. My only idea was to remove Control-J.

j-bennet commented 3 years ago

@rolandwalker You could make Control + J binding conditional, and not bind it in unit tests, like this:

import os
from prompt_toolkit.filters import Condition

@Condition
def no_cpr():
    """Only if PROMPT_TOOLKIT_NO_CPR."""
    return os.environ.get('PROMPT_TOOLKIT_NO_CPR', '') == '1'

then:

@kb.add('c-j', filter=~no_cpr)

However, I don't know all the implications of overriding the default binding of c-j. prompt_toolkit handles c-j in a few places, example:

https://github.com/prompt-toolkit/python-prompt-toolkit/blob/4c2fb15e7f4838d46467b0ca193ae6d543b4172a/prompt_toolkit/key_binding/bindings/basic.py#L186

maybe @jonathanslenders can advise here?

rolandwalker commented 3 years ago

In the latest push, I am just removing the Control-J binding.

j-bennet commented 3 years ago

@rolandwalker are you able to rebase this on master?

rolandwalker commented 3 years ago

@j-bennet rebased

j-bennet commented 3 years ago

👍 Merged. Thank you!