1
1
mirror of https://github.com/dbcli/pgcli.git synced 2024-10-06 10:17:15 +03:00

Merge pull request #442 from jonathanslenders/prompt-toolkit-0.57

Upgrade to prompt-toolkit-0.57
This commit is contained in:
Amjith Ramanujam 2016-01-18 07:22:05 -08:00
commit 9d87e8fd6f
5 changed files with 22 additions and 22 deletions

View File

@ -17,6 +17,8 @@ def pgcli_bindings(get_vi_mode_enabled, set_vi_mode_enabled):
key_binding_manager = KeyBindingManager(
enable_open_in_editor=True,
enable_system_bindings=True,
enable_search=True,
enable_abort_and_exit_bindings=True,
enable_vi_mode=Condition(lambda cli: get_vi_mode_enabled()))
@key_binding_manager.registry.add_binding(Keys.F2)

View File

@ -23,9 +23,11 @@ except ImportError:
import sqlparse
from prompt_toolkit import CommandLineInterface, Application, AbortAction
from prompt_toolkit.enums import DEFAULT_BUFFER
from prompt_toolkit.shortcuts import create_default_layout, create_eventloop
from prompt_toolkit.shortcuts import create_prompt_layout
from prompt_toolkit.buffer import AcceptAction
from prompt_toolkit.document import Document
from prompt_toolkit.filters import Always, HasFocus, IsDone
from prompt_toolkit.layout.lexers import PygmentsLexer
from prompt_toolkit.layout.processors import (ConditionalProcessor,
HighlightMatchingBracketProcessor)
from prompt_toolkit.history import FileHistory
@ -391,9 +393,9 @@ class PGCli(object):
get_toolbar_tokens = create_toolbar_tokens_func(
lambda: self.vi_mode, self.completion_refresher.is_refreshing)
layout = create_default_layout(
lexer=PostgresLexer,
reserve_space_for_menu=True,
layout = create_prompt_layout(
lexer=PygmentsLexer(PostgresLexer),
reserve_space_for_menu=4,
get_prompt_tokens=prompt_tokens,
get_bottom_toolbar_tokens=get_toolbar_tokens,
display_completions_in_columns=self.wider_completion_menu,
@ -410,7 +412,8 @@ class PGCli(object):
always_multiline=self.multi_line,
completer=self.completer,
history=history,
complete_while_typing=Always())
complete_while_typing=Always(),
accept_action=AcceptAction.RETURN_DOCUMENT)
application = Application(
style=style_factory(self.syntax_style, self.cli_style),
@ -418,11 +421,10 @@ class PGCli(object):
buffer=buf,
key_bindings_registry=key_binding_manager.registry,
on_exit=AbortAction.RAISE_EXCEPTION,
on_abort=AbortAction.RETRY,
ignore_case=True)
cli = CommandLineInterface(
application=application,
eventloop=create_eventloop())
cli = CommandLineInterface(application=application)
return cli

View File

@ -1,7 +1,6 @@
from pygments.token import string_to_tokentype
from pygments.style import Style
from pygments.util import ClassNotFound
from prompt_toolkit.styles import default_style_extensions
from prompt_toolkit.styles import PygmentsStyle
import pygments.styles
@ -11,12 +10,8 @@ def style_factory(name, cli_style):
except ClassNotFound:
style = pygments.styles.get_style_by_name('native')
class PGStyle(Style):
styles = {}
custom_styles = dict([(string_to_tokentype(x), y)
for x, y in cli_style.items()])
styles.update(style.styles)
styles.update(default_style_extensions)
custom_styles = dict([(string_to_tokentype(x), y)
for x, y in cli_style.items()])
styles.update(custom_styles)
return PGStyle
return PygmentsStyle.from_defaults(style_dict=custom_styles,
pygments_style_cls=style)

View File

@ -1,4 +1,5 @@
from pygments.token import Token
from prompt_toolkit.enums import DEFAULT_BUFFER
def create_toolbar_tokens_func(get_vi_mode_enabled, get_is_refreshing):
@ -13,17 +14,17 @@ def create_toolbar_tokens_func(get_vi_mode_enabled, get_is_refreshing):
result = []
result.append((token, ' '))
if cli.buffers['default'].completer.smart_completion:
if cli.buffers[DEFAULT_BUFFER].completer.smart_completion:
result.append((token.On, '[F2] Smart Completion: ON '))
else:
result.append((token.Off, '[F2] Smart Completion: OFF '))
if cli.buffers['default'].always_multiline:
if cli.buffers[DEFAULT_BUFFER].always_multiline:
result.append((token.On, '[F3] Multiline: ON '))
else:
result.append((token.Off, '[F3] Multiline: OFF '))
if cli.buffers['default'].always_multiline:
if cli.buffers[DEFAULT_BUFFER].always_multiline:
result.append((token,
' (Semi-colon [;] will end the line)'))

View File

@ -15,7 +15,7 @@ install_requirements = [
'pgspecial>=1.1.0',
'click >= 4.1',
'Pygments >= 2.0', # Pygments has to be Capitalcased. WTF?
'prompt_toolkit==0.46',
'prompt_toolkit==0.57',
'psycopg2 >= 2.5.4',
'sqlparse == 0.1.16',
'configobj >= 5.0.6',