How to use the ptpython.prompt_style.PromptStyle function in ptpython

To help you get started, we’ve selected a few ptpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jonathanslenders / ptpdb / ptpdb / layout.py View on Github external
from ptpython.prompt_style import PromptStyle

from pygments.token import Token
from pygments.lexers import PythonLexer

import linecache
import os

__all__ = (
    'PdbPromptStyle',
    'CallStack',
    'format_stack_entry',
)

class PdbPromptStyle(PromptStyle):
    """
    Pdb prompt.

    Show "(pdb)" when we have a pdb command or '>>>' when the user types a
    Python command.
    """
    def __init__(self, pdb_commands):
        self.pdb_commands = pdb_commands

    def in_tokens(self, cli):
        b = cli.buffers[DEFAULT_BUFFER]

        command = b.document.text.lstrip()
        if command:
            command = command.split()[0]
github prompt-toolkit / ptpython / ptpython / prompt_style.py View on Github external
def in2_prompt(self, width):
        return [
            ('class:in', '...: '.rjust(width)),
        ]

    def out_prompt(self):
        return [
            ('class:out', 'Out['),
            ('class:out.number', '%s' % self.python_input.current_statement_index),
            ('class:out', ']:'),
            ('', ' '),
        ]


class ClassicPrompt(PromptStyle):
    """
    The classic Python prompt.
    """
    def in_prompt(self):
        return [('class:prompt', '>>> ')]

    def in2_prompt(self, width):
        return [('class:prompt.dots', '...')]

    def out_prompt(self):
        return []
github prompt-toolkit / ptpython / examples / python-embed-with-custom-prompt.py View on Github external
def configure(repl):
    # There are several ways to override the prompt.

    # 1. Probably, the best is to add a new PromptStyle to `all_prompt_styles`
    #    and activate it. This way, the other styles are still selectable from
    #    the menu.
    class CustomPrompt(PromptStyle):
        def in_tokens(self, cli):
            return [
                (Token.In, 'Input['),
                (Token.In.Number, '%s' % repl.current_statement_index),
                (Token.In, '] >>: '),
            ]

        def in2_tokens(self, cli, width):
           return [
                (Token.In, '...: '.rjust(width)),
            ]

        def out_tokens(self, cli):
            return [
                (Token.Out, 'Result['),
                (Token.Out.Number, '%s' % repl.current_statement_index),
github prompt-toolkit / ptpython / ptpython / prompt_style.py View on Github external
def in2_prompt(self, width):
        """
        Tokens for every following input line.

        :param width: The available width. This is coming from the width taken
                      by `in_prompt`.
        """
        return []

    @abstractmethod
    def out_prompt(self):
        " Return the output tokens. "
        return []


class IPythonPrompt(PromptStyle):
    """
    A prompt resembling the IPython prompt.
    """
    def __init__(self, python_input):
        self.python_input = python_input

    def in_prompt(self):
        return [
            ('class:in', 'In ['),
            ('class:in.number', '%s' % self.python_input.current_statement_index),
            ('class:in', ']: '),
        ]

    def in2_prompt(self, width):
        return [
            ('class:in', '...: '.rjust(width)),
github prompt-toolkit / ptpython / ptpython / ipython.py View on Github external
from .style import default_ui_style

from IPython.terminal.embed import InteractiveShellEmbed as _InteractiveShellEmbed
from IPython.terminal.ipapp import load_default_config
from IPython import utils as ipy_utils
from IPython.core.inputsplitter import IPythonInputSplitter

from pygments.lexers import PythonLexer, BashLexer
from ptpython.prompt_style import PromptStyle

__all__ = (
    'embed',
)


class IPythonPrompt(PromptStyle):
    """
    Style for IPython >5.0, use the prompt_toolkit tokens directly.
    """
    def __init__(self, prompts):
        self.prompts = prompts

    def in_prompt(self):
        return PygmentsTokens(self.prompts.in_prompt_tokens())

    def in2_prompt(self, width):
        return PygmentsTokens(self.prompts.continuation_prompt_tokens())

    def out_prompt(self):
        return []