Python prompt_toolkit.styles.merge_styles() Examples
The following are 8
code examples of prompt_toolkit.styles.merge_styles().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
prompt_toolkit.styles
, or try the search function
.
Example #1
Source File: pgstyle.py From pgcli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def style_factory(name, cli_style): try: style = pygments.styles.get_style_by_name(name) except ClassNotFound: style = pygments.styles.get_style_by_name("native") prompt_styles = [] # prompt-toolkit used pygments tokens for styling before, switched to style # names in 2.0. Convert old token types to new style names, for backwards compatibility. for token in cli_style: if token.startswith("Token."): # treat as pygments token (1.0) token_type, style_value = parse_pygments_style(token, style, cli_style) if token_type in TOKEN_TO_PROMPT_STYLE: prompt_style = TOKEN_TO_PROMPT_STYLE[token_type] prompt_styles.append((prompt_style, style_value)) else: # we don't want to support tokens anymore logger.error("Unhandled style / class name: %s", token) else: # treat as prompt style name (2.0). See default style names here: # https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py prompt_styles.append((token, cli_style[token])) override_style = Style([("bottom-toolbar", "noreverse")]) return merge_styles( [style_from_pygments_cls(style), override_style, Style(prompt_styles)] )
Example #2
Source File: style.py From ptpython with BSD 3-Clause "New" or "Revised" License | 5 votes |
def generate_style(python_style: BaseStyle, ui_style: BaseStyle) -> BaseStyle: """ Generate Pygments Style class from two dictionaries containing style rules. """ return merge_styles([python_style, ui_style]) # Code style for Windows consoles. They support only 16 colors, # so we choose a combination that displays nicely.
Example #3
Source File: clistyle.py From litecli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def style_factory(name, cli_style): try: style = pygments.styles.get_style_by_name(name) except ClassNotFound: style = pygments.styles.get_style_by_name("native") prompt_styles = [] # prompt-toolkit used pygments tokens for styling before, switched to style # names in 2.0. Convert old token types to new style names, for backwards compatibility. for token in cli_style: if token.startswith("Token."): # treat as pygments token (1.0) token_type, style_value = parse_pygments_style(token, style, cli_style) if token_type in TOKEN_TO_PROMPT_STYLE: prompt_style = TOKEN_TO_PROMPT_STYLE[token_type] prompt_styles.append((prompt_style, style_value)) else: # we don't want to support tokens anymore logger.error("Unhandled style / class name: %s", token) else: # treat as prompt style name (2.0). See default style names here: # https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py prompt_styles.append((token, cli_style[token])) override_style = Style([("bottom-toolbar", "noreverse")]) return merge_styles( [style_from_pygments_cls(style), override_style, Style(prompt_styles)] )
Example #4
Source File: clistyle.py From athenacli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def style_factory(name, cli_style): try: style = pygments.styles.get_style_by_name(name) except ClassNotFound: style = pygments.styles.get_style_by_name('native') prompt_styles = [] # prompt-toolkit used pygments tokens for styling before, switched to style # names in 2.0. Convert old token types to new style names, for backwards compatibility. for token in cli_style: if token.startswith('Token.'): # treat as pygments token (1.0) token_type, style_value = parse_pygments_style( token, style, cli_style) if token_type in TOKEN_TO_PROMPT_STYLE: prompt_style = TOKEN_TO_PROMPT_STYLE[token_type] prompt_styles.append((prompt_style, style_value)) else: # we don't want to support tokens anymore logger.error('Unhandled style / class name: %s', token) else: # treat as prompt style name (2.0). See default style names here: # https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py prompt_styles.append((token, cli_style[token])) override_style = Style([('bottom-toolbar', 'noreverse')]) return merge_styles([ style_from_pygments_cls(style), override_style, Style(prompt_styles) ])
Example #5
Source File: mssqlstyle.py From mssql-cli with BSD 3-Clause "New" or "Revised" License | 5 votes |
def style_factory(name, cli_style): try: style = pygments.styles.get_style_by_name(name) except ClassNotFound: style = pygments.styles.get_style_by_name('native') prompt_styles = [] # prompt-toolkit used pygments tokens for styling before, switched to style # names in 2.0. Convert old token types to new style names, for backwards compatibility. for token in cli_style: if token.startswith('Token.'): # treat as pygments token (1.0) token_type, style_value = parse_pygments_style( token, style, cli_style) if token_type in TOKEN_TO_PROMPT_STYLE: prompt_style = TOKEN_TO_PROMPT_STYLE[token_type] prompt_styles.append((prompt_style, style_value)) else: # we don't want to support tokens anymore logger.error('Unhandled style / class name: %s', token) else: # treat as prompt style name (2.0). See default style names here: # https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py prompt_styles.append((token, cli_style[token])) override_style = Style([('bottom-toolbar', 'noreverse')]) return merge_styles([ style_from_pygments_cls(style), override_style, Style(prompt_styles) ])
Example #6
Source File: style.py From pyvim with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_editor_style_by_name(name): """ Get Style class. This raises `pygments.util.ClassNotFound` when there is no style with this name. """ if name == 'vim': vim_style = Style.from_dict(default_vim_style) else: vim_style = style_from_pygments_cls(get_style_by_name(name)) return merge_styles([ vim_style, Style.from_dict(style_extensions), ])
Example #7
Source File: session_prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def get_style(self): return merge_styles([super().get_style(), Style.from_dict(constants.STYLE)]) # --------------------------------------------------------------- #
Example #8
Source File: text.py From questionary with MIT License | 4 votes |
def text( message: Text, default: Text = "", validate: Any = None, qmark: Text = DEFAULT_QUESTION_PREFIX, style: Optional[Style] = None, **kwargs: Any ) -> Question: """Prompt the user to enter a free text message. This question type can be used to prompt the user for some text input. Args: message: Question text default: Default value will be returned if the user just hits enter. validate: Require the entered value to pass a validation. The value can not be submited until the validator accepts it (e.g. to check minimum password length). This can either be a function accepting the input and returning a boolean, or an class reference to a subclass of the prompt toolkit Validator class. qmark: Question prefix displayed in front of the question. By default this is a `?` style: A custom color and style for the question parts. You can configure colors as well as font types for different elements. Returns: Question: Question instance, ready to be prompted (using `.ask()`). """ merged_style = merge_styles([DEFAULT_STYLE, style]) validator = build_validator(validate) def get_prompt_tokens() -> List[Tuple[Text, Text]]: return [("class:qmark", qmark), ("class:question", " {} ".format(message))] p = PromptSession( get_prompt_tokens, style=merged_style, validator=validator, **kwargs ) p.default_buffer.reset(Document(default)) return Question(p.app)