Python prompt_toolkit.styles.Style.from_dict() Examples
The following are 15
code examples of prompt_toolkit.styles.Style.from_dict().
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.Style
, or try the search function
.
Example #1
Source File: __main__.py From chepy with GNU General Public License v3.0 | 6 votes |
def get_style(): return Style.from_dict( { "completion-menu.completion.current": "bg:#00aaaa #000000", # "completion-menu.completion": "bg:#008888 #ffffff", "completion-menu.completion.fuzzymatch.outside": "fg:#00aaaa", "prompt1": "{} bold".format(prompt_colors[0]), "prompt2": "{} bold".format(prompt_colors[1]), "prompt3": "{} bold".format(prompt_colors[2]), "state_index": "#ffd700", "rprompt": "fg:{}".format(config.prompt_rprompt), "bottom-toolbar": config.prompt_bottom_toolbar, "prompt_toolbar_version": "bg:{}".format(config.prompt_toolbar_version), "prompt_toolbar_states": "bg:{}".format(config.prompt_toolbar_states), "prompt_toolbar_buffers": "bg:{}".format(config.prompt_toolbar_buffers), "prompt_toolbar_type": "bg:{}".format(config.prompt_toolbar_type), "prompt_toolbar_plugins": "bg:{}".format(config.prompt_toolbar_plugins), "prompt_toolbar_errors": "bg:{}".format(config.prompt_toolbar_errors), } )
Example #2
Source File: print-formatted-text.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 6 votes |
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"))
Example #3
Source File: ipython.py From ptpython with BSD 3-Clause "New" or "Revised" License | 5 votes |
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, lambda: self.enable_dictionary_completion, ) kw["_lexer"] = create_lexer() kw["_validator"] = IPythonValidator(get_compiler_flags=self.get_compiler_flags) super().__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")
Example #4
Source File: style.py From ptpython with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_all_code_styles() -> Dict[str, BaseStyle]: """ Return a mapping from style names to their classes. """ result: Dict[str, BaseStyle] = { 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
Example #5
Source File: style.py From ptpython with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_all_ui_styles() -> Dict[str, BaseStyle]: """ Return a dict mapping {ui_style_name -> style_dict}. """ return { "default": Style.from_dict(default_ui_style), "blue": Style.from_dict(blue_ui_style), }
Example #6
Source File: cli.py From chepy with GNU General Public License v3.0 | 5 votes |
def print_in_colors(out): style = Style.from_dict({"cli_out": "fg:{}".format(config.cli_info_color)}) print_formatted_text(FormattedText([("class:cli_out", str(out))]), style=style)
Example #7
Source File: pygments-tokens.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #8
Source File: test_print_formatted_text.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_formatted_text_with_style(): f = _Capture() style = Style.from_dict({"hello": "#ff0066", "world": "#44ff44 italic",}) tokens = FormattedText([("class:hello", "Hello "), ("class:world", "world"),]) # NOTE: We pass the default (8bit) color depth, so that the unit tests # don't start failing when environment variables change. pt_print(tokens, style=style, file=f, color_depth=ColorDepth.DEFAULT) assert b"\x1b[0;38;5;197mHello" in f.data assert b"\x1b[0;38;5;83;3mworld" in f.data
Example #9
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 #10
Source File: prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def get_style(self): Style.from_dict({ 'completion-menu.completion': 'bg:#008888 #ffffff', 'completion-menu.completion.current': 'bg:#00aaaa #000000', 'scrollbar.background': 'bg:#88aaaa', 'scrollbar.button': 'bg:#222222', 'token.literal.string.single': '#98ff75' }) # --------------------------------------------------------------- #
Example #11
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 #12
Source File: fuzz_logger_text.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def _print_log_msg(self, msg_type, msg=None, data=None): try: print_formatted_text(helpers.color_formatted_text(helpers.format_log_msg(msg_type=msg_type, description=msg, data=data, indent_size=self.INDENT_SIZE), msg_type), file=self._file_handle, style=Style.from_dict(STYLE)) except: print_formatted_text(helpers.format_log_msg(msg_type=msg_type, description=msg, data=data, indent_size=self.INDENT_SIZE), file=self._file_handle, style=Style.from_dict(STYLE))
Example #13
Source File: style.py From hummingbot with Apache License 2.0 | 5 votes |
def load_style(): """ Return a dict mapping {ui_style_name -> style_dict}. """ if is_windows(): return Style.from_dict(win32_code_style) else: return Style.from_dict(default_ui_style)
Example #14
Source File: console.py From python-sploitkit with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, parent=None, **kwargs): super(Console, self).__init__() # determine the relevant parent self.parent = parent if self.parent is not None and self.parent.level == self.level: while parent is not None and parent.level == self.level: parent = parent.parent # go up of one console level # raise an exception in the context of command's .run() execution, # to be propagated to console's .run() execution, setting the # directly higher level console in argument raise ConsoleDuplicate(self, parent) # back-reference the console self.config.console = self # configure the console regarding its parenthood if self.parent is None: if Console.parent is not None: raise Exception("Only one parent console can be used") Console.parent = self Console.parent._start_time = datetime.now() Console.appdispname = Console.appname Console.appname = Console.appname.lower() self.__init(**kwargs) else: self.parent.child = self # reset commands and other bound stuffs self.reset() # setup the session with the custom completer and validator completer, validator = CommandCompleter(), CommandValidator() completer.console = validator.console = self message, style = self.prompt hpath = Path(self.config.option("WORKSPACE").value).joinpath("history") self._session = PromptSession( message, completer=completer, history=FileHistory(hpath), validator=validator, style=Style.from_dict(style), ) CustomLayout(self)
Example #15
Source File: bottom-toolbar.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 4 votes |
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=0.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)