summaryrefslogtreecommitdiffstats
path: root/mycli/clibuffer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-02-08 11:28:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-02-08 11:28:14 +0000
commitb678a621c57a6d3fdfac14bdbbef0ed743ab1742 (patch)
tree5481c14ce75dfda9c55721de033992b45ab0e1dc /mycli/clibuffer.py
parentInitial commit. (diff)
downloadmycli-b678a621c57a6d3fdfac14bdbbef0ed743ab1742.tar.xz
mycli-b678a621c57a6d3fdfac14bdbbef0ed743ab1742.zip
Adding upstream version 1.22.2.upstream/1.22.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mycli/clibuffer.py')
-rw-r--r--mycli/clibuffer.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/mycli/clibuffer.py b/mycli/clibuffer.py
new file mode 100644
index 0000000..c9d29d1
--- /dev/null
+++ b/mycli/clibuffer.py
@@ -0,0 +1,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 == '')
+ )