summaryrefslogtreecommitdiffstats
path: root/pgcli/pgbuffer.py
blob: 0dbf43d378893919e3c15c7cd4a3818f231b9f51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from prompt_toolkit.buffer import Buffer

class PGBuffer(Buffer):
    def __init__(self, always_multiline, *args, **kwargs):
        self.always_multiline = always_multiline
        is_multiline = lambda doc: self.always_multiline and not _multiline_exception(doc.text)
        super(PGBuffer, self).__init__(*args, is_multiline=is_multiline, **kwargs)

def _multiline_exception(text):
    text = text.strip()
    return (text.startswith('\\') or   # Special Command
            text.endswith('\e') or     # Ended with \e which should launch the editor.
            text.endswith(';') or      # Ended with a semi-colon
            (text == 'exit') or        # Exit doesn't need semi-colon
            (text == 'quit') or        # Quit doesn't need semi-colon
            (text == ':q') or          # To all the vim fans out there
            (text == '')               # Just a plain enter without any text
            )