-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathclibuffer.py
More file actions
39 lines (32 loc) · 1.23 KB
/
Copy pathclibuffer.py
File metadata and controls
39 lines (32 loc) · 1.23 KB
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
from prompt_toolkit.enums import DEFAULT_BUFFER
from prompt_toolkit.filters import Condition
from prompt_toolkit.application import get_app
def cli_is_multiline(cli):
@Condition
def cond():
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
if not cli.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 (
text.startswith("\\")
or text.endswith(";") # Special Command
or text.endswith("\\g") # Ended with a semi-colon
or text.endswith("\\G") # Ended with \g
or (text == "exit") # Ended with \G
or (text == "quit") # Exit doesn't need semi-colon
or (text == ":q") # Quit doesn't need semi-colon
or ( # To all the vim fans out there
text == ""
) # Just a plain enter without any text
)