Ejemplo n.º 1
0
    def __init__(self, input_handler: Callable, bindings: KeyBindings,
                 completer: Completer):
        use_asyncio_event_loop()
        self.input_field = create_input_field(completer=completer)
        self.output_field = create_output_field()
        self.log_field = create_log_field()
        self.layout = generate_layout(self.input_field, self.output_field,
                                      self.log_field)

        self.bindings = bindings
        self.input_handler = input_handler
        self.input_field.accept_handler = self.accept
        self.app = Application(layout=self.layout,
                               full_screen=True,
                               key_bindings=self.bindings,
                               style=load_style(),
                               mouse_support=True,
                               clipboard=PyperclipClipboard())
        self.log_lines: Deque[str] = deque()
        self.log(HEADER)

        # settings
        self.prompt_text = ">>> "
        self.pending_input = None
        self.input_event = None
        self.hide_input = False
Ejemplo n.º 2
0
    def __init__(self, **kwargs):
        ptk_args = kwargs.pop("ptk_args", {})
        super().__init__(**kwargs)
        if ON_WINDOWS:
            winutils.enable_virtual_terminal_processing()
        self._first_prompt = True
        self.history = ThreadedHistory(PromptToolkitHistory())

        ptk_args.setdefault("history", self.history)
        if not XSH.env.get("XONSH_COPY_ON_DELETE", False):
            disable_copy_on_deletion()
        if HAVE_SYS_CLIPBOARD:
            ptk_args.setdefault("clipboard", PyperclipClipboard())
        self.prompter: PromptSession = PromptSession(**ptk_args)

        self.prompt_formatter = PTKPromptFormatter(self)
        self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx, self)
        ptk_bindings = self.prompter.app.key_bindings
        self.key_bindings = load_xonsh_bindings(ptk_bindings)
        self._overrides_deprecation_warning_shown = False

        # Store original `_history_matches` in case we need to restore it
        self._history_matches_orig = self.prompter.default_buffer._history_matches
        # This assumes that PromptToolkitShell is a singleton
        events.on_ptk_create.fire(
            prompter=self.prompter,
            history=self.history,
            completer=self.pt_completer,
            bindings=self.key_bindings,
        )
        # Goes at the end, since _MergedKeyBindings objects do not have
        # an add() function, which is necessary for on_ptk_create events
        self.key_bindings = merge_key_bindings(
            [self.key_bindings, load_emacs_shift_selection_bindings()]
        )
Ejemplo n.º 3
0
    def __init__(self, input_handler: Callable, bindings: KeyBindings,
                 completer: Completer):
        self.search_field = create_search_field()
        self.input_field = create_input_field(completer=completer)
        self.output_field = create_output_field()
        self.log_field = create_log_field(self.search_field)
        self.layout = generate_layout(self.input_field, self.output_field,
                                      self.log_field, self.search_field)
        # add self.to_stop_config to know if cancel is triggered
        self.to_stop_config: bool = False

        self.bindings = bindings
        self.input_handler = input_handler
        self.input_field.accept_handler = self.accept
        self.app = Application(layout=self.layout,
                               full_screen=True,
                               key_bindings=self.bindings,
                               style=load_style(),
                               mouse_support=True,
                               clipboard=PyperclipClipboard())

        # settings
        self.prompt_text = ">>> "
        self.pending_input = None
        self.input_event = None
        self.hide_input = False
Ejemplo n.º 4
0
    def __init__(self):
        self.lira = LiraApp()
        self.lira.setup()

        self.content = ContentArea(self)
        self.status = StatusBar(self)
        self.menu = SidebarMenu(self)

        self.container = HSplit(
            [
                VSplit(
                    [
                        self.menu,
                        self.content,
                    ],
                    padding=Dimension.exact(1),
                    padding_char="│",
                    padding_style=theme["separator"],
                ),
                self.status,
            ],
            padding=Dimension.exact(1),
            padding_char="─",
            padding_style=theme["separator"],
        )
        self.app = Application(
            layout=Layout(self.container),
            key_bindings=self.get_key_bindings(),
            mouse_support=True,
            full_screen=True,
            style=style,
            after_render=self._ready,
            clipboard=PyperclipClipboard(),
        )
Ejemplo n.º 5
0
    def _init_prompt(self):
        if self.batch_mode:
            return None
        else:
            try:
                from prompt_toolkit.clipboard.pyperclip import PyperclipClipboard
                clipboard = PyperclipClipboard()
            except ImportError:
                clipboard = None

            return PromptSession(
                style=style_from_pygments_cls(PeekStyle),
                lexer=PygmentsLexer(PeekLexer),
                auto_suggest=AutoSuggestFromHistory(),
                completer=self.completer,
                history=self.history,
                multiline=True,
                key_bindings=key_bindings(self),
                enable_open_in_editor=True,
                enable_system_prompt=False,
                enable_suspend=True,
                search_ignore_case=True,
                clipboard=clipboard,
                mouse_support=Condition(self._should_support_mouse),
                swap_light_and_dark_colors=self.config.as_bool('swap_colour'),
                input_processors=[
                    HighlightMatchingBracketProcessor(chars="[](){}"),
                ],
            )
 async def run(self):
     self.app = Application(layout=self.layout,
                            full_screen=True,
                            key_bindings=self.bindings,
                            style=load_style(),
                            mouse_support=True,
                            clipboard=PyperclipClipboard())
     await self.app.run_async()
Ejemplo n.º 7
0
 async def run(self):
     self.app = Application(layout=self.layout,
                            full_screen=True,
                            key_bindings=self.bindings,
                            style=load_style(),
                            mouse_support=True,
                            clipboard=PyperclipClipboard())
     await self.app.run_async(pre_run=self.did_start_ui)
     self._stdout_redirect_context.close()
Ejemplo n.º 8
0
def interactive():
    session = PromptSession(
        completer=DshellCompleter.from_nested_dict(nested_dict),
        history=get_history('main', InMemoryHistory()),
        clipboard=PyperclipClipboard(),
        enable_history_search=True,
        enable_suspend=True)

    parser = ArgumentParserRaise(allow_abbrev=False, prog='')
    parser = create_parser(nested_dict, parser)
    while True:
        message = [
            ('class:username', env._username if env._username else "?"),
            ('class:at', '@'),
            ('class:host', env.get("SERVER") if env.get("SERVER") else "?"),
            ('', ':'),
            ('class:path', 'dshell'),
            ('', '> '),
        ]
        try:
            text = session.prompt(message, style=style)
        except KeyboardInterrupt:
            continue  # Control-C pressed. Try again.
        except EOFError:
            exit_dshell()

        if text.startswith('!'):
            subprocess.call(text.lstrip('!'), shell=True)
        else:
            try:
                namespace = parser.parse_args(shlex.split(text))
            except (ValueError, argparse.ArgumentError) as e:
                dprint(e)
                continue
            except SystemExit:
                continue
            except Exception as e:
                dprint(e)
                continue
            else:
                cmd_params = vars(namespace)

            if not text:
                continue
            elif text == 'help':
                parser.print_usage()
            elif text and len(cmd_params) == 0:
                try:
                    parser.parse_args(shlex.split(text) + ['-h'])
                except SystemExit:
                    continue
            else:
                call_func_with_signature(cmd_params)
    def build_app(self) -> ClientApplication:
        """
        Build CUI application with text editor.
        :return: ClientApplication
        """

        return ClientApplication(
            layout=Layout(self.root_container,
                          focused_element=self.text_field),
            enable_page_navigation_bindings=True,
            style=self.style,
            mouse_support=True,
            full_screen=True,
            clipboard=PyperclipClipboard(),
            show_message=self.show_message
        )
Ejemplo n.º 10
0
    def __init__(self,
                #  input_handler: Callable,
                #  completer: Completer):
                ):

        completer = None
        self.process_usage = create_process_monitor()
        
        self.search_log_field = create_search_field("logs")
        self.search_out_field = create_search_field("ouput")
        self.input_field = create_input_field(completer=completer)
        self.output_field = create_output_field(self.search_out_field)

        # right hand window
        self.log_field = create_log_field(self.search_log_field)

        self.timer = create_timer()
        self.layout = generate_layout(self.input_field, self.output_field, self.log_field, self.search_log_field, self.search_out_field, self.timer, self.process_usage)
        # add self.to_stop_config to know if cancel is triggered
        self.to_stop_config: bool = False

        self.live_updates = False
        self.bindings = load_key_bindings(self)

        self.input_handler = self._input_handler
        self.input_field.accept_handler = self.accept
        self.app = Application(layout=self.layout, full_screen=True, key_bindings=self.bindings, style=load_style(),
                               mouse_support=True, clipboard=PyperclipClipboard())

        # settings
        self.prompt_text = ">>> "
        self.pending_input = None
        self.input_event = None
        self.hide_input = False

        # start ui tasks
        self.loop = asyncio.get_event_loop()
        self.loop.create_task(start_timer(self.timer))

        #! maximaus added
        self.argparser = load_parser(self)
        self.client = httpx.AsyncClient()
        # TODO update type annotation
        self.ws: typing.Dict[str, KrakenWsPublic] = {}
        # TODO we dont want to hardcode this for every exchange
        self.symbols: typing.Dict = {}
Ejemplo n.º 11
0
 def create_app(self, focus):
     ctx = self.ctx
     ctx.cmd_buffer.on_text_changed += self.process_key
     ctx.input_buffer.on_text_changed += self.process_key
     ctx.cmd_buffer.cursor_position = len(ctx.cmd_buffer.text)
     if focus:
         focused_element = {
             "COMMAND": ctx.cmd_buffer,
             "c": ctx.cmd_buffer,
             "INPUT": ctx.input_buffer,
             "i": ctx.input_buffer,
             "OUTPUT": ctx.output_buffer,
             "o": ctx.output_buffer,
         }[focus]
     else:
         focused_element = ctx.cmd_buffer if ctx.input_buffer.text else ctx.input_buffer
     layout = Layout(
         FloatContainer(
             HSplit(
                 [
                     self.create_boxes(),
                     self.create_status_bar(),
                     self.create_cmd_bar(),
                 ]
             ),
             floats=[
                 Float(self.create_help()),
             ],
         ),
         focused_element=focused_element,
     )
     return Application(
         key_bindings=kb,
         editing_mode=EditingMode.VI,
         clipboard=PyperclipClipboard(),
         color_depth=ColorDepth.from_env() or ColorDepth.DEPTH_24_BIT,
         full_screen=True,
         mouse_support=True,
         include_default_pygments_style=False,
         style=application_style,
         layout=layout,
     )
Ejemplo n.º 12
0
    def __init__(self, input_handler: Callable, bindings: KeyBindings,
                 completer: Completer):
        self.search_field = create_search_field()
        self.input_field = create_input_field(completer=completer)
        self.output_field = create_output_field()
        self.log_field = create_log_field(self.search_field)
        self.timer = create_timer()
        self.process_usage = create_process_monitor()
        self.trade_monitor = create_trade_monitor()
        self.layout = generate_layout(self.input_field, self.output_field,
                                      self.log_field, self.search_field,
                                      self.timer, self.process_usage,
                                      self.trade_monitor)
        # add self.to_stop_config to know if cancel is triggered
        self.to_stop_config: bool = False

        self.live_updates = False
        self.bindings = bindings
        self.input_handler = input_handler
        self.input_field.accept_handler = self.accept
        self.app = Application(layout=self.layout,
                               full_screen=True,
                               key_bindings=self.bindings,
                               style=load_style(),
                               mouse_support=True,
                               clipboard=PyperclipClipboard())

        # settings
        self.prompt_text = ">>> "
        self.pending_input = None
        self.input_event = None
        self.hide_input = False

        # start ui tasks
        loop = asyncio.get_event_loop()
        loop.create_task(start_timer(self.timer))
        loop.create_task(start_process_monitor(self.process_usage))
        loop.create_task(start_trade_monitor(self.trade_monitor))
Ejemplo n.º 13
0
#!/usr/bin/env python
"""
Demonstration of a custom clipboard class.
This requires the 'pyperclip' library to be installed.
"""
from prompt_toolkit import prompt
from prompt_toolkit.clipboard.pyperclip import PyperclipClipboard

if __name__ == '__main__':
    print('Emacs shortcuts:')
    print('    Press Control-Y to paste from the system clipboard.')
    print('    Press Control-Space or Control-@ to enter selection mode.')
    print('    Press Control-W to cut to clipboard.')
    print('')

    answer = prompt('Give me some input: ', clipboard=PyperclipClipboard())
    print('You said: %s' % answer)
#!/usr/bin/env python
"""
Demonstration of a custom clipboard class.
This requires the 'pyperclip' library to be installed.
"""
from __future__ import unicode_literals
from prompt_toolkit.shortcuts import get_input
from prompt_toolkit.clipboard.pyperclip import PyperclipClipboard

if __name__ == '__main__':
    print('Emacs shortcuts:')
    print('    Press Control-Y to paste from the system clipboard.')
    print('    Press Control-Space or Control-@ to enter selection mode.')
    print('    Press Control-W to cut to clipboard.')
    print('')

    answer = get_input('Give me some input: ', clipboard=PyperclipClipboard())
    print('You said: %s' % answer)