예제 #1
0
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.

"""Bliss shell user interface style"""

from ptpython.style import get_all_ui_styles
from prompt_toolkit.token import Token

__all__ = ('bliss_ui_style',)


_default = get_all_ui_styles()['default']

bliss_ui_style = dict(_default)
bliss_ui_style.update({
    Token.Toolbar.Status.Name: 'bg:#0000ff #ffffff bold',
    Token.Toolbar.Status.Label: 'bg:#222222 #ffffff bold',
    Token.Toolbar.Status.Ok: 'bg:#222222 #ffffff',
    Token.Toolbar.Status.Warning: 'bg:#ffa500 #ffffff',
    Token.Toolbar.Status.Alarm: 'bg:#aa0000 #ffffff',
    Token.Toolbar.Status.Error: 'bg:#ff00ff #ffffff',
    Token.Toolbar.Status.Changing: 'bg:#3333ff #ffffff',
    Token.Toolbar.Status.Open: 'bg:#00aa00 #ffffff',
    Token.Toolbar.Status.Close: 'bg:#aa0000 #ffffff',
})
예제 #2
0
    def __init__(self,
                 get_globals=None, get_locals=None, history_filename=None,
                 vi_mode=False,

                 # For internal use.
                 _completer=None, _validator=None, _python_prompt_control=None,
                 _lexer=None, _extra_buffers=None, _extra_buffer_processors=None,
                 _on_start=None,
                 _extra_layout_body=None, _extra_toolbars=None,
                 _input_buffer_height=None,
                 _accept_action=AcceptAction.RETURN_DOCUMENT,
                 _on_exit=AbortAction.RAISE_EXCEPTION):

        self.get_globals = get_globals or (lambda: {})
        self.get_locals = get_locals or self.get_globals

        self._completer = _completer or PythonCompleter(self.get_globals, self.get_locals)
        self._validator = _validator or PythonValidator(self.get_compiler_flags)
        self._history = FileHistory(history_filename) if history_filename else InMemoryHistory()
        self._lexer = _lexer or PygmentsLexer(PythonLexer)
        self._extra_buffers = _extra_buffers
        self._accept_action = _accept_action
        self._on_exit = _on_exit
        self._on_start = _on_start

        self._input_buffer_height = _input_buffer_height
        self._extra_layout_body = _extra_layout_body or []
        self._extra_toolbars = _extra_toolbars or []
        self._extra_buffer_processors = _extra_buffer_processors or []

        self._python_prompt_control = _python_prompt_control or PythonPrompt(self)

        # Settings.
        self.show_signature = True
        self.show_docstring = False
        self.completion_visualisation = CompletionVisualisation.MULTI_COLUMN
        self.completion_menu_scroll_offset = 1

        self.show_line_numbers = True
        self.show_status_bar = True
        self.complete_while_typing = True
        self.vi_mode = vi_mode
        self.paste_mode = False  # When True, don't insert whitespace after newline.
        self.confirm_exit = True  # Ask for confirmation when Control-D is pressed.
        self.accept_input_on_enter = 2  # Accept when pressing Enter 'n' times.
                                        # 'None' means that meta-enter is always required.
        self.enable_open_in_editor = True
        self.enable_system_bindings = True
        self.enable_input_validation = True
        self.enable_history_search = False  # When True, like readline, going
                                            # back in history will filter the
                                            # history on the records starting
                                            # with the current input.

        self.show_sidebar = False  # Currently show the sidebar.
        self.show_sidebar_help = True # When the sidebar is visible, also show the help text.
        self.show_exit_confirmation = False  # Currently show 'Do you really want to exit?'
        self.terminal_title = None  # The title to be displayed in the terminal. (None or string.)
        self.exit_message = 'Do you really want to exit?'

        #: Load styles.
        self.code_styles = get_all_code_styles()
        self.ui_styles = get_all_ui_styles()
        self._current_code_style_name = 'default'
        self._current_ui_style_name = 'default'

        if is_windows():
            self._current_code_style_name = 'win32'

        self._current_style = self._generate_style()

        # Options to be configurable from the sidebar.
        self.options = self._create_options()
        self.selected_option_index = 0

        #: Incremeting integer counting the current statement.
        self.current_statement_index = 1

        # Code signatures. (This is set asynchronously after a timeout.)
        self.signatures = []

        # Use a KeyBindingManager for loading the key bindings.
        self.key_bindings_manager = KeyBindingManager(
            enable_vi_mode=Condition(lambda cli: self.vi_mode),
            enable_open_in_editor=Condition(lambda cli: self.enable_open_in_editor),
            enable_system_bindings=Condition(lambda cli: self.enable_system_bindings),

            # Disable all default key bindings when the sidebar or the exit confirmation
            # are shown.
            enable_all=Condition(lambda cli: not (self.show_sidebar or self.show_exit_confirmation)))

        load_python_bindings(self.key_bindings_manager, self)
        load_sidebar_bindings(self.key_bindings_manager, self)
        load_confirm_exit_bindings(self.key_bindings_manager, self)

        # Boolean indicating whether we have a signatures thread running.
        # (Never run more than one at the same time.)
        self._get_signatures_thread_running = False
예제 #3
0
    def __init__(self,
                 get_globals=None, get_locals=None, history_filename=None,
                 vi_mode=False,

                 # For internal use.
                 _completer=None, _validator=None, _python_prompt_control=None,
                 _lexer=None, _extra_buffers=None, _extra_buffer_processors=None,
                 _on_start=None,
                 _extra_sidebars=None,
                 _accept_action=AcceptAction.RETURN_DOCUMENT,
                 _on_exit=AbortAction.RAISE_EXCEPTION):

        self.get_globals = get_globals or (lambda: {})
        self.get_locals = get_locals or self.get_globals

        self._completer = _completer or PythonCompleter(self.get_globals, self.get_locals)
        self._validator = _validator or PythonValidator()
        self._history = FileHistory(history_filename) if history_filename else History()
        self._lexer = _lexer or PythonLexer
        self._extra_buffers = _extra_buffers
        self._accept_action = _accept_action
        self._on_exit = _on_exit
        self._on_start = _on_start

        self._extra_sidebars = _extra_sidebars or []
        self._extra_buffer_processors = _extra_buffer_processors or []

        self._python_prompt_control = _python_prompt_control or PythonPrompt(self)

        # Settings.
        self.show_signature = True
        self.show_docstring = False
        self.show_completions_toolbar = False
        self.show_completions_menu = True
        self.show_line_numbers = True
        self.show_status_bar = True
        self.complete_while_typing = True
        self.vi_mode = vi_mode
        self.paste_mode = False  # When True, don't insert whitespace after newline.
        self.confirm_exit = True  # Ask for confirmation when Control-D is pressed.
        self.enable_open_in_editor = True
        self.enable_system_bindings = True
        self.enable_history_search = False  # When True, like readline, going
                                            # back in history will filter the
                                            # history on the records starting
                                            # with the current input.

        self.show_sidebar = False  # Currently show the sidebar.
        self.show_exit_confirmation = False  # Currently show 'Do you really want to exit?'

        #: Load styles.
        self.code_styles = get_all_code_styles()
        self.ui_styles = get_all_ui_styles()
        self._current_code_style_name = 'default'
        self._current_ui_style_name = 'default'
        self._current_style = self._generate_style()

        # Options to be configurable from the sidebar.
        def handler(enable=None, disable=None):
            " Handler for an '_Option'. "
            def handler():
                if enable:
                    for o in enable:
                        setattr(self, o, True)

                if disable:
                    for o in disable:
                        setattr(self, o, False)
            return handler

        def simple_option(description, field_name, values=None):
            " Create Simple on/of option. "
            values = values or ['off', 'on']

            def current_value():
                return values[bool(getattr(self, field_name))]

            return _Option(description, lambda: {
                values[1]: handler(enable=[field_name]),
                values[0]: handler(disable=[field_name]),
            }, current_value)

        def get_completion_menu_value():
            " Return active value for the 'completion menu' option. "
            if self.show_completions_menu:
                return 'pop-up'
            elif self.show_completions_toolbar:
                return 'toolbar'
            else:
                return 'off'

        self.options = [
            simple_option('Input mode', 'vi_mode', values=['emacs', 'vi']),
            simple_option('Paste mode', 'paste_mode'),
            _Option('Completion menu', lambda: {
                'off': handler(disable=['show_completions_menu', 'show_completions_toolbar']),
                'pop-up': handler(enable=['show_completions_menu'],
                                  disable=['show_completions_toolbar']),
                'toolbar': handler(enable=['show_completions_toolbar'],
                                  disable=['show_completions_menu'])
            }, get_completion_menu_value),
            _Option('Complete while typing', lambda: {
                'on': handler(enable=['complete_while_typing'], disable=['enable_history_search']),
                'off': handler(disable=['complete_while_typing']),
            }, lambda: ['off', 'on'][self.complete_while_typing]),
            simple_option('Show signature', 'show_signature'),
            simple_option('Show docstring', 'show_docstring'),
            simple_option('Show line numbers', 'show_line_numbers'),
            simple_option('Show status bar', 'show_status_bar'),
            _Option('History search', lambda: {
                'on': handler(enable=['enable_history_search'], disable=['complete_while_typing']),
                'off': handler(disable=['enable_history_search']),
            }, lambda: ['off', 'on'][self.enable_history_search]),
            _Option('Color scheme (code)', lambda: {
                name: partial(self.use_code_colorscheme, name) for name in self.code_styles
            }, lambda: self._current_code_style_name),
            _Option('Color scheme (UI)', lambda: {
                name: partial(self.use_ui_colorscheme, name) for name in self.ui_styles
            }, lambda: self._current_ui_style_name),
            simple_option('Confirm on exit', 'confirm_exit'),
        ]
        self.selected_option = 0

        #: Incremeting integer counting the current statement.
        self.current_statement_index = 1

        # Code signatures. (This is set asynchronously after a timeout.)
        self.signatures = []

        # Use a KeyBindingManager for loading the key bindings.
        self.key_bindings_manager = KeyBindingManager(
            enable_vi_mode=Condition(lambda cli: self.vi_mode),
            enable_open_in_editor=Condition(lambda cli: self.enable_open_in_editor),
            enable_system_bindings=Condition(lambda cli: self.enable_system_bindings),

            # Disable all default key bindings when the sidebar or the exit confirmation
            # are shown.
            enable_all=Condition(lambda cli: not (self.show_sidebar or self.show_exit_confirmation)))

        load_python_bindings(self.key_bindings_manager, self)
        load_sidebar_bindings(self.key_bindings_manager, self)
        load_confirm_exit_bindings(self.key_bindings_manager, self)

        # Boolean indicating whether we have a signatures thread running.
        # (Never run more than one at the same time.)
        self._get_signatures_thread_running = False
예제 #4
0
    def __init__(self,
                 get_globals=None, get_locals=None, history_filename=None,
                 vi_mode=False,

                 # For internal use.
                 _completer=None, _validator=None,
                 _lexer=None, _extra_buffers=None, _extra_buffer_processors=None,
                 _on_start=None,
                 _extra_layout_body=None, _extra_toolbars=None,
                 _input_buffer_height=None,
                 _accept_action=AcceptAction.RETURN_DOCUMENT,
                 _on_exit=AbortAction.RAISE_EXCEPTION):

        self.get_globals = get_globals or (lambda: {})
        self.get_locals = get_locals or self.get_globals

        self._completer = _completer or PythonCompleter(self.get_globals, self.get_locals)
        self._validator = _validator or PythonValidator(self.get_compiler_flags)
        self.history = FileHistory(history_filename) if history_filename else InMemoryHistory()
        self._lexer = _lexer or PygmentsLexer(PythonLexer)
        self._extra_buffers = _extra_buffers
        self._accept_action = _accept_action
        self._on_exit = _on_exit
        self._on_start = _on_start

        self._input_buffer_height = _input_buffer_height
        self._extra_layout_body = _extra_layout_body or []
        self._extra_toolbars = _extra_toolbars or []
        self._extra_buffer_processors = _extra_buffer_processors or []

        # Settings.
        self.settings = Settings({
            'show_signature': True,
            'show_docstring': False,
            'show_meta_enter_message': True,
            'completion_visualisation': 'CompletionVisualisation.MULTI_COLUMN',
            'completion_menu_scroll_offset': 1,
            
            'show_line_numbers': False,
            'show_status_bar': True,
            'wrap_lines': True,
            'complete_while_typing': True,
            'vi_mode': vi_mode,
            'paste_mode': False,  # When True, don't insert whitespace after newline.
            'confirm_exit': True,  # Ask for confirmation when Control-D is pressed.
            'accept_input_on_enter': 2,  # Accept when pressing Enter 'n' times.
                                         # 'None' means that meta-enter is always required.
            'enable_open_in_editor': True,
            'enable_system_bindings': True,
            'enable_input_validation': True,
            'enable_auto_suggest': False,
            'enable_mouse_support': False,
            'enable_history_search': False,  # When True, like readline, going
                                             # back in history will filter the
                                             # history on the records starting
                                             # with the current input.
            
            'highlight_matching_parenthesis': True,
            'show_sidebar': False,  # Currently show the sidebar.
            'show_sidebar_help': True, # When the sidebar is visible, also show the help text.
            'terminal_title': None,  # The title to be displayed in the terminal. (None or string.)
            'exit_message': 'Do you really want to exit?',
            
            # Tokens to be shown at the prompt.
            'prompt_style': 'classic'  # The currently active style.
        })

        self.show_exit_confirmation = False

        self.all_prompt_styles = {  # Styles selectable from the menu.
            'ipython': IPythonPrompt(self),
            'classic': ClassicPrompt(),
        }

        self.get_input_prompt_tokens = lambda cli: \
            self.all_prompt_styles[self.settings.prompt_style].in_tokens(cli)

        self.get_output_prompt_tokens = lambda cli: \
            self.all_prompt_styles[self.settings.prompt_style].out_tokens(cli)

        #: Load styles.
        self.code_styles = get_all_code_styles()
        self.ui_styles = get_all_ui_styles()
        self._current_code_style_name = 'default'
        self._current_ui_style_name = 'default'

        if is_windows():
            self._current_code_style_name = 'win32'

        self._current_style = self._generate_style()

        # Options to be configurable from the sidebar.
        self.options = self._create_options()
        self.selected_option_index = 0

        #: Incremeting integer counting the current statement.
        self.current_statement_index = 1

        # Code signatures. (This is set asynchronously after a timeout.)
        self.signatures = []

        # Use a KeyBindingManager for loading the key bindings.
        self.key_bindings_manager = KeyBindingManager(
            enable_abort_and_exit_bindings=True,
            enable_search=True,
            enable_vi_mode=Condition(lambda cli: self.settings.vi_mode),
            enable_open_in_editor=Condition(lambda cli: self.settings.enable_open_in_editor),
            enable_system_bindings=Condition(lambda cli: self.settings.enable_system_bindings),
            enable_auto_suggest_bindings=Condition(lambda cli: self.settings.enable_auto_suggest),

            # Disable all default key bindings when the sidebar or the exit confirmation
            # are shown.
            enable_all=Condition(lambda cli: not (self.settings.show_sidebar or self.show_exit_confirmation)))

        load_python_bindings(self.key_bindings_manager, self)
        load_sidebar_bindings(self.key_bindings_manager, self)
        load_confirm_exit_bindings(self.key_bindings_manager, self)

        # Boolean indicating whether we have a signatures thread running.
        # (Never run more than one at the same time.)
        self._get_signatures_thread_running = False
예제 #5
0
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
"""Bliss shell user interface style"""

from ptpython.style import get_all_ui_styles
from prompt_toolkit.token import Token

__all__ = ('bliss_ui_style', )

_default = get_all_ui_styles()['default']

bliss_ui_style = dict(_default)
bliss_ui_style.update({
    Token.Toolbar.Status.Name: 'bg:#0000ff #ffffff bold',
    Token.Toolbar.Status.Label: 'bg:#222222 #ffffff bold',
    Token.Toolbar.Status.Ok: 'bg:#222222 #ffffff',
    Token.Toolbar.Status.Warning: 'bg:#ffa500 #ffffff',
    Token.Toolbar.Status.Alarm: 'bg:#aa0000 #ffffff',
    Token.Toolbar.Status.Error: 'bg:#ff00ff #ffffff',
    Token.Toolbar.Status.Changing: 'bg:#3333ff #ffffff',
    Token.Toolbar.Status.Open: 'bg:#00aa00 #ffffff',
    Token.Toolbar.Status.Close: 'bg:#aa0000 #ffffff',
})
예제 #6
0
    def __init__(self,
                 get_globals=None, get_locals=None, history_filename=None,
                 vi_mode=False,

                 # For internal use.
                 _completer=None, _validator=None,
                 _lexer=None, _extra_buffers=None, _extra_buffer_processors=None,
                 _on_start=None,
                 _extra_layout_body=None, _extra_toolbars=None,
                 _input_buffer_height=None,
                 _accept_action=AcceptAction.RETURN_DOCUMENT,
                 _on_exit=AbortAction.RAISE_EXCEPTION):

        self.get_globals = get_globals or (lambda: {})
        self.get_locals = get_locals or self.get_globals

        self._completer = _completer or PythonCompleter(self.get_globals, self.get_locals)
        self._validator = _validator or PythonValidator(self.get_compiler_flags)
        self.history = FileHistory(history_filename) if history_filename else InMemoryHistory()
        self._lexer = _lexer or PygmentsLexer(PythonLexer)
        self._extra_buffers = _extra_buffers
        self._accept_action = _accept_action
        self._on_exit = _on_exit
        self._on_start = _on_start

        self._input_buffer_height = _input_buffer_height
        self._extra_layout_body = _extra_layout_body or []
        self._extra_toolbars = _extra_toolbars or []
        self._extra_buffer_processors = _extra_buffer_processors or []

        # Settings.
        self.show_signature = False
        self.show_docstring = False
        self.show_meta_enter_message = True
        self.completion_visualisation = CompletionVisualisation.MULTI_COLUMN
        self.completion_menu_scroll_offset = 1

        self.show_line_numbers = False
        self.show_status_bar = True
        self.wrap_lines = True
        self.complete_while_typing = True
        self.vi_mode = vi_mode
        self.paste_mode = False  # When True, don't insert whitespace after newline.
        self.confirm_exit = True  # Ask for confirmation when Control-D is pressed.
        self.accept_input_on_enter = 2  # Accept when pressing Enter 'n' times.
                                        # 'None' means that meta-enter is always required.
        self.enable_open_in_editor = True
        self.enable_system_bindings = True
        self.enable_input_validation = True
        self.enable_auto_suggest = False
        self.enable_mouse_support = False
        self.enable_history_search = False  # When True, like readline, going
                                            # back in history will filter the
                                            # history on the records starting
                                            # with the current input.

        self.highlight_matching_parenthesis = False
        self.show_sidebar = False  # Currently show the sidebar.
        self.show_sidebar_help = True # When the sidebar is visible, also show the help text.
        self.show_exit_confirmation = False  # Currently show 'Do you really want to exit?'
        self.terminal_title = None  # The title to be displayed in the terminal. (None or string.)
        self.exit_message = 'Do you really want to exit?'

        # Tokens to be shown at the prompt.
        self.prompt_style = 'classic'  # The currently active style.

        self.all_prompt_styles = {  # Styles selectable from the menu.
            'ipython': IPythonPrompt(self),
            'classic': ClassicPrompt(),
        }

        self.get_input_prompt_tokens = lambda cli: \
            self.all_prompt_styles[self.prompt_style].in_tokens(cli)

        self.get_output_prompt_tokens = lambda cli: \
            self.all_prompt_styles[self.prompt_style].out_tokens(cli)

        #: Load styles.
        self.code_styles = get_all_code_styles()
        self.ui_styles = get_all_ui_styles()
        self._current_code_style_name = 'default'
        self._current_ui_style_name = 'default'

        if is_windows():
            self._current_code_style_name = 'win32'

        self._current_style = self._generate_style()
        self.true_color = False

        # Options to be configurable from the sidebar.
        self.options = self._create_options()
        self.selected_option_index = 0

        #: Incremeting integer counting the current statement.
        self.current_statement_index = 1

        # Code signatures. (This is set asynchronously after a timeout.)
        self.signatures = []

        # Use a KeyBindingManager for loading the key bindings.
        self.key_bindings_manager = KeyBindingManager(
            enable_abort_and_exit_bindings=True,
            enable_search=True,
            enable_vi_mode=Condition(lambda cli: self.vi_mode),
            enable_open_in_editor=Condition(lambda cli: self.enable_open_in_editor),
            enable_system_bindings=Condition(lambda cli: self.enable_system_bindings),
            enable_auto_suggest_bindings=Condition(lambda cli: self.enable_auto_suggest),

            # Disable all default key bindings when the sidebar or the exit confirmation
            # are shown.
            enable_all=Condition(lambda cli: not (self.show_sidebar or self.show_exit_confirmation)))

        load_python_bindings(self.key_bindings_manager, self)
        load_sidebar_bindings(self.key_bindings_manager, self)
        load_confirm_exit_bindings(self.key_bindings_manager, self)

        # Boolean indicating whether we have a signatures thread running.
        # (Never run more than one at the same time.)
        self._get_signatures_thread_running = False