summaryrefslogtreecommitdiffstats
path: root/litecli/clibuffer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2020-08-14 16:58:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-02-07 10:11:48 +0000
commit4edd467b28c895483cd5468d51d1c6824a21715a (patch)
tree04a4f32d617905acfc23653025b6e8d3899f51c6 /litecli/clibuffer.py
parentInitial commit. (diff)
downloadlitecli-4edd467b28c895483cd5468d51d1c6824a21715a.tar.xz
litecli-4edd467b28c895483cd5468d51d1c6824a21715a.zip
Adding upstream version 1.5.0.upstream/1.5.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'litecli/clibuffer.py')
-rw-r--r--litecli/clibuffer.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/litecli/clibuffer.py b/litecli/clibuffer.py
new file mode 100644
index 0000000..a57192a
--- /dev/null
+++ b/litecli/clibuffer.py
@@ -0,0 +1,40 @@
+from __future__ import unicode_literals
+
+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("\\") # Special Command
+ or text.endswith(";") # Ended with a semi-colon
+ or text.endswith("\\g") # Ended with \g
+ or text.endswith("\\G") # Ended with \G
+ or (text == "exit") # Exit doesn't need semi-colon
+ or (text == "quit") # Quit doesn't need semi-colon
+ or (text == ":q") # To all the vim fans out there
+ or (text == "") # Just a plain enter without any text
+ )