blob: c9d29d1ddfd19f54a3a70f21f4b02ff167a64bd7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
from prompt_toolkit.enums import DEFAULT_BUFFER
from prompt_toolkit.filters import Condition
from prompt_toolkit.application import get_app
from .packages.parseutils import is_open_quote
from .packages import special
def cli_is_multiline(mycli):
@Condition
def cond():
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
if not mycli.multi_line:
return False
else:
return not _multiline_exception(doc.text)
return cond
def _multiline_exception(text):
orig = text
text = text.strip()
# Multi-statement favorite query is a special case. Because there will
# be a semicolon separating statements, we can't consider semicolon an
# EOL. Let's consider an empty line an EOL instead.
if text.startswith('\\fs'):
return orig.endswith('\n')
return (
# Special Command
text.startswith('\\') or
# Delimiter declaration
text.lower().startswith('delimiter') or
# Ended with the current delimiter (usually a semi-column)
text.endswith(special.get_current_delimiter()) or
text.endswith('\\g') or
text.endswith('\\G') or
# Exit doesn't need semi-column`
(text == 'exit') or
# Quit doesn't need semi-column
(text == 'quit') or
# To all teh vim fans out there
(text == ':q') or
# just a plain enter without any text
(text == '')
)
|