當前位置: 首頁>>代碼示例>>Python>>正文


Python styles.Style類代碼示例

本文整理匯總了Python中prompt_toolkit.styles.Style的典型用法代碼示例。如果您正苦於以下問題:Python Style類的具體用法?Python Style怎麽用?Python Style使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Style類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_all_ui_styles

def get_all_ui_styles():
    """
    Return a dict mapping {ui_style_name -> style_dict}.
    """
    return {
        'default': Style.from_dict(default_ui_style),
        'blue': Style.from_dict(blue_ui_style),
    }
開發者ID:jonathanslenders,項目名稱:ptpython,代碼行數:8,代碼來源:style.py

示例2: test_substyles

def test_substyles():
    style = Style([
        ('a.b', '#ff0000 bold'),
        ('a', '#0000ff'),
        ('b', '#00ff00'),
        ('b.c', '#0000ff italic'),
    ])

    # Starting with a.*
    expected = Attrs(color='0000ff', bgcolor='', bold=False, underline=False,
                     italic=False, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:a') == expected

    expected = Attrs(color='ff0000', bgcolor='', bold=True, underline=False,
                     italic=False, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:a.b') == expected
    assert style.get_attrs_for_style_str('class:a.b.c') == expected

    # Starting with b.*
    expected = Attrs(color='00ff00', bgcolor='', bold=False, underline=False,
                     italic=False, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:b') == expected
    assert style.get_attrs_for_style_str('class:b.a') == expected

    expected = Attrs(color='0000ff', bgcolor='', bold=False, underline=False,
                     italic=True, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:b.c') == expected
    assert style.get_attrs_for_style_str('class:b.c.d') == expected
開發者ID:tsvenson,項目名稱:python-prompt-toolkit,代碼行數:28,代碼來源:test_style.py

示例3: __init__

    def __init__(self, ipython_shell, *a, **kw):
        kw['_completer'] = create_completer(kw['get_globals'], kw['get_globals'],
                                            ipython_shell.magics_manager,
                                            ipython_shell.alias_manager)
        kw['_lexer'] = create_lexer()
        kw['_validator'] = IPythonValidator(
            get_compiler_flags=self.get_compiler_flags)

        super(IPythonInput, self).__init__(*a, **kw)
        self.ipython_shell = ipython_shell

        self.all_prompt_styles['ipython'] = IPythonPrompt(ipython_shell.prompts)
        self.prompt_style = 'ipython'

        # UI style for IPython. Add tokens that are used by IPython>5.0
        style_dict = {}
        style_dict.update(default_ui_style)
        style_dict.update({
            'pygments.prompt':        '#009900',
            'pygments.prompt-num':     '#00ff00 bold',
            'pygments.out-prompt':     '#990000',
            'pygments.out-prompt-num':  '#ff0000 bold',
        })

        self.ui_styles = {
            'default': Style.from_dict(style_dict),
        }
        self.use_ui_colorscheme('default')
開發者ID:jonathanslenders,項目名稱:ptpython,代碼行數:28,代碼來源:ipython.py

示例4: main

def main():
    style = Style.from_dict({
        'hello': '#ff0066',
        'world': '#44ff44 italic',
    })

    # Print using a a list of text fragments.
    text_fragments = FormattedText([
        ('class:hello', 'Hello '),
        ('class:world', 'World'),
        ('', '\n'),
    ])
    print(text_fragments, style=style)

    # Print using an HTML object.
    print(HTML(
        '<hello>hello</hello> <world>world</world>\n'),
        style=style)

    # Print using an HTML object with inline styling.
    print(HTML(
        '<style fg="#ff0066">hello</style> '
        '<style fg="#44ff44"><i>world</i></style>\n'))

    # Print using ANSI escape sequences.
    print(ANSI(
        '\x1b[31mhello \x1b[32mworld\n'))
開發者ID:jonathanslenders,項目名稱:python-prompt-toolkit,代碼行數:27,代碼來源:print-formatted-text.py

示例5: test_style_from_dict

def test_style_from_dict():
    style = Style.from_dict({
        'a': '#ff0000 bold underline italic',
        'b': 'bg:#00ff00 blink reverse',
    })

    # Lookup of class:a.
    expected = Attrs(color='ff0000', bgcolor='', bold=True, underline=True,
                     italic=True, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:a') == expected

    # Lookup of class:b.
    expected = Attrs(color='', bgcolor='00ff00', bold=False, underline=False,
                     italic=False, blink=True, reverse=True, hidden=False)
    assert style.get_attrs_for_style_str('class:b') == expected

    # Test inline style.
    expected = Attrs(color='ff0000', bgcolor='', bold=False, underline=False,
                     italic=False, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('#ff0000') == expected

    # Combine class name and inline style (Whatever is defined later gets priority.)
    expected = Attrs(color='00ff00', bgcolor='', bold=True, underline=True,
                     italic=True, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:a #00ff00') == expected

    expected = Attrs(color='ff0000', bgcolor='', bold=True, underline=True,
                     italic=True, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('#00ff00 class:a') == expected
開發者ID:tsvenson,項目名稱:python-prompt-toolkit,代碼行數:29,代碼來源:test_style.py

示例6: get_all_code_styles

def get_all_code_styles():
    """
    Return a mapping from style names to their classes.
    """
    result = dict((name, style_from_pygments_cls(get_style_by_name(name))) for name in get_all_styles())
    result['win32'] = Style.from_dict(win32_code_style)
    return result
開發者ID:jonathanslenders,項目名稱:ptpython,代碼行數:7,代碼來源:style.py

示例7: test_with_style

def test_with_style():
    f = _Capture()
    style = Style.from_dict({
        'hello': '#ff0066',
        'world': '#44ff44 italic',
    })
    tokens = FormattedText([
        ('class:hello', 'Hello '),
        ('class:world', 'world'),
    ])
    pt_print(tokens, style=style, file=f)
    assert b'\x1b[0;38;5;197mHello' in f.data
    assert b'\x1b[0;38;5;83;3mworld' in f.data
開發者ID:tsvenson,項目名稱:python-prompt-toolkit,代碼行數:13,代碼來源:test_print_formatted_text.py

示例8: main

def main():
    # Example 1: fixed text.
    text = prompt('Say something: ', bottom_toolbar='This is a toolbar')
    print('You said: %s' % text)

    # Example 2: fixed text from a callable:
    def get_toolbar():
        return 'Bottom toolbar: time=%r' % time.time()

    text = prompt('Say something: ', bottom_toolbar=get_toolbar,
                  refresh_interval=.5)
    print('You said: %s' % text)

    # Example 3: Using HTML:
    text = prompt('Say something: ', bottom_toolbar=HTML(
        '(html) <b>This</b> <u>is</u> a <style bg="ansired">toolbar</style>'))
    print('You said: %s' % text)

    # Example 4: Using ANSI:
    text = prompt('Say something: ', bottom_toolbar=ANSI(
        '(ansi): \x1b[1mThis\x1b[0m \x1b[4mis\x1b[0m a \x1b[91mtoolbar'))
    print('You said: %s' % text)

    # Example 5: styling differently.
    style = Style.from_dict({
        'bottom-toolbar':      '#aaaa00 bg:#ff0000',
        'bottom-toolbar.text': '#aaaa44 bg:#aa4444',
    })

    text = prompt('Say something: ', bottom_toolbar='This is a toolbar',
                  style=style)
    print('You said: %s' % text)

    # Example 6: Using a list of tokens.
    def get_bottom_toolbar():
        return [
            ('', ' '),
            ('bg:#ff0000 fg:#000000', 'This'),
            ('', ' is a '),
            ('bg:#ff0000 fg:#000000', 'toolbar'),
            ('', '. '),
        ]

    text = prompt('Say something: ', bottom_toolbar=get_bottom_toolbar)
    print('You said: %s' % text)

    # Example 7: multiline fixed text.
    text = prompt('Say something: ', bottom_toolbar='This is\na multiline toolbar')
    print('You said: %s' % text)
開發者ID:jonathanslenders,項目名稱:python-prompt-toolkit,代碼行數:49,代碼來源:bottom-toolbar.py

示例9: __init__

    def __init__(self, player):
        self.player = player
        self.playerClans = ' '.join(self.player.clantags)
        if len(self.player.clantags) > 0 : 
            self.playerName = FormattedText([
                ('#ffffff', player.aspect['name']),
                ('', ' '),
                ('#cc00cc', self.playerClans, "utf-8"),
            ]) 
        else: 
            self.playerClans =  self.playerName = FormattedText([
                ('#ffffff', player.aspect['name']),
            ]) 
        self.result = None

        self.mainRadiosRows = []
        self.listOfItems = []
        self.populateMainRadios() # declares self.mainRadios
        self.currentRadios = self.mainRadios
        self.description = self.mainRadios.description # description is whataver is in the description box on the right
        self.requestingConfirmation = False
        
        self.bindings = KeyBindings()
        self.bindings.add('right' )(focus_next)
        self.bindings.add('tab' )(focus_next)
        self.bindings.add('s-tab')(focus_previous)
        self.bindings.add('left')(focus_previous)
        self.bindings.add('c-m')(self.handleEnter)
        self.bindings.add('escape')(self.handleEscape)

        self.style = Style.from_dict({
            'dialog.body':        'bg:#000000 #ffcccc', #background color, text color
        })

        self.application = Application(
            layout=Layout(
                self.getRootContainer(),
                focused_element=self.mainRadios,
            ),
            key_bindings=self.bindings,
            style=self.style,
            mouse_support=True,
            full_screen=True,
            )
開發者ID:DreamTeamXtreme,項目名稱:Adventure,代碼行數:44,代碼來源:inventoryUI.py

示例10: test_class_combinations_1

def test_class_combinations_1():
    # In this case, our style has both class 'a' and 'b'.
    # Given that the style for 'a b' is defined at the end, that one is used.
    style = Style([
        ('a', '#0000ff'),
        ('b', '#00ff00'),
        ('a b', '#ff0000'),
    ])
    expected = Attrs(color='ff0000', bgcolor='', bold=False, underline=False,
                     italic=False, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:a class:b') == expected
    assert style.get_attrs_for_style_str('class:a,b') == expected
    assert style.get_attrs_for_style_str('class:a,b,c') == expected

    # Changing the order shouldn't matter.
    assert style.get_attrs_for_style_str('class:b class:a') == expected
    assert style.get_attrs_for_style_str('class:b,a') == expected
開發者ID:tsvenson,項目名稱:python-prompt-toolkit,代碼行數:17,代碼來源:test_style.py

示例11: main

def main():
    # Printing a manually constructed list of (Token, text) tuples.
    text = [
        (Token.Keyword, 'print'),
        (Token.Punctuation, '('),
        (Token.Literal.String.Double, '"'),
        (Token.Literal.String.Double, 'hello'),
        (Token.Literal.String.Double, '"'),
        (Token.Punctuation, ')'),
        (Token.Text, '\n'),
    ]

    print_formatted_text(PygmentsTokens(text))

    # Printing the output of a pygments lexer.
    tokens = list(pygments.lex('print("Hello")', lexer=PythonLexer()))
    print_formatted_text(PygmentsTokens(tokens))

    # With a custom style.
    style = Style.from_dict({
        'pygments.keyword': 'underline',
        'pygments.literal.string': 'bg:#00ff00 #ffffff',
    })
    print_formatted_text(PygmentsTokens(tokens), style=style)
開發者ID:tsvenson,項目名稱:python-prompt-toolkit,代碼行數:24,代碼來源:pygments-tokens.py

示例12: test_class_combinations_2

def test_class_combinations_2():
    # In this case, our style has both class 'a' and 'b'.
    # The style that is defined the latest get priority.
    style = Style([
        ('a b', '#ff0000'),
        ('b', '#00ff00'),
        ('a', '#0000ff'),
    ])
    expected = Attrs(color='00ff00', bgcolor='', bold=False, underline=False,
                     italic=False, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:a class:b') == expected
    assert style.get_attrs_for_style_str('class:a,b') == expected
    assert style.get_attrs_for_style_str('class:a,b,c') == expected

    # Defining 'a' latest should give priority to 'a'.
    expected = Attrs(color='0000ff', bgcolor='', bold=False, underline=False,
                     italic=False, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:b class:a') == expected
    assert style.get_attrs_for_style_str('class:b,a') == expected
開發者ID:tsvenson,項目名稱:python-prompt-toolkit,代碼行數:19,代碼來源:test_style.py

示例13: bottom_toolbar

from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.styles import Style
from termcolor import colored
from terminaltables import AsciiTable

import core.state as state
from core.listeners import Listeners
from core.modules import Modules
from core.sessions import Sessions
from core.stagers import Stagers
from core.utils import print_bad, print_banner

rprompt_style = Style.from_dict({
    'rprompt': 'bg:#ff0066 #ffffff',
})


def bottom_toolbar():
    return HTML(f"(Sessions: {state.SESSIONS} Listeners: {state.LISTENERS})")


def get_rprompt(error=False):
    return ' Error ' if error else ''


class UserExit(Exception):
    pass

開發者ID:vaginessa,項目名稱:SILENTTRINITY,代碼行數:29,代碼來源:st.py

示例14: main

#!/usr/bin/env python
"""
Styled similar to tqdm, another progress bar implementation in Python.

See: https://github.com/noamraph/tqdm
"""
import time

from prompt_toolkit.shortcuts import ProgressBar
from prompt_toolkit.shortcuts.progress_bar import formatters
from prompt_toolkit.styles import Style

style = Style.from_dict({
    '': 'cyan',
})


def main():
    custom_formatters = [
        formatters.Label(suffix=': '),
        formatters.Bar(start='|', end='|', sym_a='#', sym_b='#', sym_c='-'),
        formatters.Text(' '),
        formatters.Progress(),
        formatters.Text(' '),
        formatters.Percentage(),
        formatters.Text(' [elapsed: '),
        formatters.TimeElapsed(),
        formatters.Text(' left: '),
        formatters.TimeLeft(),
        formatters.Text(', '),
        formatters.IterationsPerSecond(),
開發者ID:jonathanslenders,項目名稱:python-prompt-toolkit,代碼行數:31,代碼來源:styled-tqdm-1.py

示例15: main

#!/usr/bin/env python
"""
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
from __future__ import unicode_literals
from prompt_toolkit.shortcuts import ProgressBar
from prompt_toolkit.styles import Style
import time

style = Style.from_dict({
    'title': '#4444ff underline',
    'label': '#ff4400 bold',
    'percentage': '#00ff00',
    'bar-a': 'bg:#00ff00 #004400',
    'bar-b': 'bg:#00ff00 #000000',
    'bar-c': '#000000 underline',
    'current': '#448844',
    'total': '#448844',
    'time-elapsed': '#444488',
    'time-left': 'bg:#88ff88 #000000',
})


def main():
    with ProgressBar(style=style, title='Progress bar example with custom styling.') as pb:
        for i in pb(range(1600), label='Downloading...'):
            time.sleep(.01)


if __name__ == '__main__':
    main()
開發者ID:tsvenson,項目名稱:python-prompt-toolkit,代碼行數:32,代碼來源:styled-1.py


注:本文中的prompt_toolkit.styles.Style類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。