diff options
author | Amjith Ramanujam <amjith.r@gmail.com> | 2016-09-12 14:28:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-12 14:28:05 -0700 |
commit | a0f1826be39bccb651bee58ccf3f5c95a76aeb6b (patch) | |
tree | 6962acb328ee66041523ef0f6f96b2104767c543 | |
parent | f76a7b0a585ec91e8010f806d69f64374960bcc0 (diff) | |
parent | 99868bbc3167834f4785ac4ad327f5491e424232 (diff) |
Merge pull request #577 from dbcli/koljonen/multiline_enter
Make semicolon not trigger execution in multiline mode
-rwxr-xr-x | pgcli/main.py | 2 | ||||
-rw-r--r-- | pgcli/pgbuffer.py | 11 | ||||
-rw-r--r-- | pgcli/pgclirc | 7 | ||||
-rw-r--r-- | pgcli/pgtoolbar.py | 6 |
4 files changed, 22 insertions, 4 deletions
diff --git a/pgcli/main.py b/pgcli/main.py index 5b2469f0..f0226e67 100755 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -121,6 +121,7 @@ class PGCli(object): self.pgspecial = PGSpecial() self.multi_line = c['main'].as_bool('multi_line') + self.multiline_mode = c['main'].get('multi_line_mode', 'psql') self.vi_mode = c['main'].as_bool('vi') self.pgspecial.timing_enabled = c['main'].as_bool('timing') if row_limit is not None: @@ -515,6 +516,7 @@ class PGCli(object): with self._completer_lock: buf = PGBuffer( always_multiline=self.multi_line, + multiline_mode=self.multiline_mode, completer=self.completer, history=history, complete_while_typing=Always(), diff --git a/pgcli/pgbuffer.py b/pgcli/pgbuffer.py index b9e9b930..15494305 100644 --- a/pgcli/pgbuffer.py +++ b/pgcli/pgbuffer.py @@ -4,13 +4,20 @@ from .packages.parseutils.utils import is_open_quote class PGBuffer(Buffer): - def __init__(self, always_multiline, *args, **kwargs): + def __init__(self, always_multiline, multiline_mode, *args, **kwargs): self.always_multiline = always_multiline + self.multiline_mode = multiline_mode @Condition def is_multiline(): doc = self.document - return self.always_multiline and not _multiline_exception(doc.text) + if not self.always_multiline: + return False + if self.multiline_mode == 'safe': + return True + else: + return not _multiline_exception(doc.text) + super(self.__class__, self).__init__(*args, is_multiline=is_multiline, tempfile_suffix='.sql', **kwargs) diff --git a/pgcli/pgclirc b/pgcli/pgclirc index 92a2c414..7b7f6f5b 100644 --- a/pgcli/pgclirc +++ b/pgcli/pgclirc @@ -15,6 +15,13 @@ wider_completion_menu = False # lines. End of line (return) is considered as the end of the statement. multi_line = False +# If multi_line_mode is set to "psql", in multi-line mode, [Enter] will execute +# the current input if the input ends in a semicolon. +# If multi_line_mode is set to "safe", in multi-line mode, [Enter] will always +# insert a newline, and [Esc] [Enter] or [Alt]-[Enter] must be used to execute +# a command. +multi_line_mode = psql + # If set to True, table suggestions will include a table alias generate_aliases = False diff --git a/pgcli/pgtoolbar.py b/pgcli/pgtoolbar.py index fa8abcb4..74144bb9 100644 --- a/pgcli/pgtoolbar.py +++ b/pgcli/pgtoolbar.py @@ -25,8 +25,10 @@ def create_toolbar_tokens_func(get_vi_mode_enabled, get_is_refreshing): result.append((token.Off, '[F3] Multiline: OFF ')) if cli.buffers[DEFAULT_BUFFER].always_multiline: - result.append((token, - ' (Semi-colon [;] will end the line)')) + if cli.buffers[DEFAULT_BUFFER].multiline_mode == 'safe': + result.append((token,' ([Esc] [Enter] to execute]) ')) + else: + result.append((token,' (Semi-colon [;] will end the line) ')) if get_vi_mode_enabled(): result.append((token.On, '[F4] Vi-mode')) |