def print_color(self, string, end="\n", **kwargs): """Prints a color string using prompt-toolkit color management.""" if isinstance(string, str): tokens = partial_color_tokenize(string) else: # assume this is a list of (Token, str) tuples and just print tokens = string tokens = PygmentsTokens(tokens) env = XSH.env style_overrides_env = env.get("XONSH_STYLE_OVERRIDES", {}) if HAS_PYGMENTS: self.styler.style_name = env.get("XONSH_COLOR_STYLE") self.styler.override(style_overrides_env) proxy_style = _style_from_pygments_cls( pyghooks.xonsh_style_proxy(self.styler)) else: proxy_style = merge_styles([ _style_from_pygments_dict(DEFAULT_STYLE_DICT), _style_from_pygments_dict(style_overrides_env), ]) ptk_print( tokens, style=proxy_style, end=end, include_default_pygments_style=False, **kwargs, )
def print_color(self, string, hide=False, **kwargs): if isinstance(string, str): s = self.format_color(string, hide=hide) else: # assume this is a list of (Token, str) tuples and format it env = builtins.__xonsh_env__ self.styler.style_name = env.get('XONSH_COLOR_STYLE') style_proxy = pyghooks.xonsh_style_proxy(self.styler) formatter = terminal256.Terminal256Formatter(style=style_proxy) s = pygments.format(string, formatter).rstrip() print(s, **kwargs)
def print_color(self, string, hide=False, **kwargs): if isinstance(string, str): s = self.format_color(string, hide=hide) else: # assume this is a list of (Token, str) tuples and format it env = builtins.__xonsh_env__ self.styler.style_name = env.get('XONSH_COLOR_STYLE') style_proxy = pyghooks.xonsh_style_proxy(self.styler) formatter = terminal256.Terminal256Formatter(style=style_proxy) s = pygments.format(string, formatter).rstrip() print(s, **kwargs)
def print_color(self, string, hide=False, **kwargs): if isinstance(string, str): s = self.format_color(string, hide=hide) else: # assume this is a list of (Token, str) tuples and format it env = XSH.env style_overrides_env = env.get("XONSH_STYLE_OVERRIDES", {}) self.styler.style_name = env.get("XONSH_COLOR_STYLE") self.styler.override(style_overrides_env) style_proxy = pyghooks.xonsh_style_proxy(self.styler) formatter = pyghooks.XonshTerminal256Formatter(style=style_proxy) s = pygments.format(string, formatter).rstrip() print(s, **kwargs)
def print_color(self, string, end='\n', **kwargs): """Prints a color string using prompt-toolkit color management.""" if isinstance(string, str): tokens = partial_color_tokenize(string + end) else: # assume this is a list of (Token, str) tuples and just print tokens = string if HAS_PYGMENTS: env = builtins.__xonsh_env__ self.styler.style_name = env.get('XONSH_COLOR_STYLE') proxy_style = PygmentsStyle(pyghooks.xonsh_style_proxy(self.styler)) else: proxy_style = style_from_dict(DEFAULT_STYLE_DICT) print_tokens(tokens, style=proxy_style)
def print_color(self, string, end='\n', **kwargs): """Prints a color string using prompt-toolkit color management.""" if isinstance(string, str): tokens = partial_color_tokenize(string + end) else: # assume this is a list of (Token, str) tuples and just print tokens = string if HAS_PYGMENTS: env = builtins.__xonsh_env__ self.styler.style_name = env.get('XONSH_COLOR_STYLE') proxy_style = PygmentsStyle(pyghooks.xonsh_style_proxy(self.styler)) else: proxy_style = style_from_dict(DEFAULT_STYLE_DICT) print_tokens(tokens, style=proxy_style)
def format_color(self, string, hide=False, force_string=False, **kwargs): """Formats a color string using Pygments. This, therefore, returns a list of (Token, str) tuples. If force_string is set to true, though, this will return a color formatted string. """ tokens = partial_color_tokenize(string) if force_string and HAS_PYGMENTS: env = builtins.__xonsh__.env self.styler.style_name = env.get("XONSH_COLOR_STYLE") proxy_style = pyghooks.xonsh_style_proxy(self.styler) formatter = pyghooks.XonshTerminal256Formatter(style=proxy_style) s = pygments.format(tokens, formatter) return s elif force_string: print("To force colorization of string, install Pygments") return tokens else: return tokens
def format_color(self, string, hide=False, force_string=False, **kwargs): """Formats a color string using Pygments. This, therefore, returns a list of (Token, str) tuples. If force_string is set to true, though, this will return a color formatted string. """ tokens = partial_color_tokenize(string) if force_string and HAS_PYGMENTS: env = builtins.__xonsh_env__ self.styler.style_name = env.get("XONSH_COLOR_STYLE") proxy_style = pyghooks.xonsh_style_proxy(self.styler) formatter = pyghooks.XonshTerminal256Formatter(style=proxy_style) s = pygments.format(tokens, formatter) return s elif force_string: print("To force colorization of string, install Pygments") return tokens else: return tokens
def print_color(self, string, end="\n", **kwargs): """Prints a color string using prompt-toolkit color management.""" if isinstance(string, str): tokens = partial_color_tokenize(string) else: # assume this is a list of (Token, str) tuples and just print tokens = string tokens = PygmentsTokens(tokens) if HAS_PYGMENTS: env = builtins.__xonsh__.env self.styler.style_name = env.get("XONSH_COLOR_STYLE") proxy_style = style_from_pygments_cls( pyghooks.xonsh_style_proxy(self.styler) ) else: proxy_style = style_from_pygments_dict(DEFAULT_STYLE_DICT) ptk_print( tokens, style=proxy_style, end=end, include_default_pygments_style=False )
def print_color(self, string, hide=False, **kwargs): """Prints a string in color. This base implementation's colors are based on ANSI color codes if a string was given as input. If a list of token pairs is given, it will color based on pygments, if available. If pygments is not available, it will print a colorless string. """ if isinstance(string, str): s = self.format_color(string, hide=hide) elif HAS_PYGMENTS: # assume this is a list of (Token, str) tuples and format it env = builtins.__xonsh__.env self.styler.style_name = env.get("XONSH_COLOR_STYLE") style_proxy = pyghooks.xonsh_style_proxy(self.styler) formatter = pyghooks.XonshTerminal256Formatter(style=style_proxy) s = pygments.format(string, formatter).rstrip() else: # assume this is a list of (Token, str) tuples and remove color s = "".join([x for _, x in string]) print(s, **kwargs)
def print_color(self, string, hide=False, **kwargs): """Prints a string in color. This base implementation's colors are based on ANSI color codes if a string was given as input. If a list of token pairs is given, it will color based on pygments, if available. If pygments is not available, it will print a colorless string. """ if isinstance(string, str): s = self.format_color(string, hide=hide) elif HAS_PYGMENTS: # assume this is a list of (Token, str) tuples and format it env = builtins.__xonsh__.env self.styler.style_name = env.get("XONSH_COLOR_STYLE") style_proxy = pyghooks.xonsh_style_proxy(self.styler) formatter = pyghooks.XonshTerminal256Formatter(style=style_proxy) s = pygments.format(string, formatter).rstrip() else: # assume this is a list of (Token, str) tuples and remove color s = "".join([x for _, x in string]) print(s, **kwargs)
def print_color(self, string, end="\n", **kwargs): """Prints a color string using prompt-toolkit color management.""" if isinstance(string, str): tokens = partial_color_tokenize(string) else: # assume this is a list of (Token, str) tuples and just print tokens = string tokens = PygmentsTokens(tokens) if HAS_PYGMENTS: env = builtins.__xonsh__.env self.styler.style_name = env.get("XONSH_COLOR_STYLE") proxy_style = style_from_pygments_cls( pyghooks.xonsh_style_proxy(self.styler)) else: proxy_style = style_from_pygments_dict(DEFAULT_STYLE_DICT) ptk_print(tokens, style=proxy_style, end=end, include_default_pygments_style=False)
def get_prompt_style(self): env = XSH.env style_overrides_env = env.get("PTK_STYLE_OVERRIDES", {}).copy() if ( len(style_overrides_env) > 0 and not self._overrides_deprecation_warning_shown ): print_warning( "$PTK_STYLE_OVERRIDES is deprecated, use $XONSH_STYLE_OVERRIDES instead!" ) self._overrides_deprecation_warning_shown = True style_overrides_env.update(env.get("XONSH_STYLE_OVERRIDES", {})) if HAS_PYGMENTS: style = _style_from_pygments_cls(pyghooks.xonsh_style_proxy(self.styler)) if len(self.styler.non_pygments_rules) > 0: try: style = merge_styles( [ style, _style_from_pygments_dict(self.styler.non_pygments_rules), ] ) except (AttributeError, TypeError, ValueError) as style_exception: print_warning( f"Error applying style override!\n{style_exception}\n" ) else: style = _style_from_pygments_dict(DEFAULT_STYLE_DICT) if len(style_overrides_env) > 0: try: style = merge_styles( [style, _style_from_pygments_dict(style_overrides_env)] ) except (AttributeError, TypeError, ValueError) as style_exception: print_warning(f"Error applying style override!\n{style_exception}\n") return style
def singleline(self, store_in_history=True, auto_suggest=None, enable_history_search=True, multiline=True, **kwargs): """Reads a single line of input from the shell. The store_in_history kwarg flags whether the input should be stored in PTK's in-memory history. """ events.on_pre_prompt.fire() env = builtins.__xonsh_env__ mouse_support = env.get("MOUSE_SUPPORT") if store_in_history: history = self.history else: history = None enable_history_search = False auto_suggest = auto_suggest if env.get("AUTO_SUGGEST") else None completions_display = env.get("COMPLETIONS_DISPLAY") multicolumn = completions_display == "multi" complete_while_typing = env.get("UPDATE_COMPLETIONS_ON_KEYPRESS") if complete_while_typing: # PTK requires history search to be none when completing while typing enable_history_search = False if HAS_PYGMENTS: self.styler.style_name = env.get("XONSH_COLOR_STYLE") completer = None if completions_display == "none" else self.pt_completer if not env.get("UPDATE_PROMPT_ON_KEYPRESS"): prompt_tokens_cached = self.prompt_tokens(None) get_prompt_tokens = lambda cli: prompt_tokens_cached rprompt_tokens_cached = self.rprompt_tokens(None) get_rprompt_tokens = lambda cli: rprompt_tokens_cached bottom_toolbar_tokens_cached = self.bottom_toolbar_tokens(None) get_bottom_toolbar_tokens = lambda cli: bottom_toolbar_tokens_cached else: get_prompt_tokens = self.prompt_tokens get_rprompt_tokens = self.rprompt_tokens get_bottom_toolbar_tokens = self.bottom_toolbar_tokens with self.prompter: prompt_args = { "mouse_support": mouse_support, "auto_suggest": auto_suggest, "get_prompt_tokens": get_prompt_tokens, "get_rprompt_tokens": get_rprompt_tokens, "get_bottom_toolbar_tokens": get_bottom_toolbar_tokens, "completer": completer, "multiline": multiline, "get_continuation_tokens": self.continuation_tokens, "history": history, "enable_history_search": enable_history_search, "reserve_space_for_menu": 0, "key_bindings_registry": self.key_bindings_manager.registry, "display_completions_in_columns": multicolumn, "complete_while_typing": complete_while_typing, } if builtins.__xonsh_env__.get("COLOR_INPUT"): if HAS_PYGMENTS: prompt_args["lexer"] = PygmentsLexer(pyghooks.XonshLexer) prompt_args["style"] = PygmentsStyle( pyghooks.xonsh_style_proxy(self.styler)) else: prompt_args["style"] = style_from_dict(DEFAULT_STYLE_DICT) line = self.prompter.prompt(**prompt_args) events.on_post_prompt.fire() return line
def singleline(self, store_in_history=True, auto_suggest=None, enable_history_search=True, multiline=True, **kwargs): """Reads a single line of input from the shell. The store_in_history kwarg flags whether the input should be stored in PTK's in-memory history. """ events.on_pre_prompt.fire() env = builtins.__xonsh_env__ mouse_support = env.get('MOUSE_SUPPORT') if store_in_history: history = self.history else: history = None enable_history_search = False auto_suggest = auto_suggest if env.get('AUTO_SUGGEST') else None completions_display = env.get('COMPLETIONS_DISPLAY') multicolumn = (completions_display == 'multi') complete_while_typing = env.get('UPDATE_COMPLETIONS_ON_KEYPRESS') if complete_while_typing: # PTK requires history search to be none when completing while typing enable_history_search = False if HAS_PYGMENTS: self.styler.style_name = env.get('XONSH_COLOR_STYLE') completer = None if completions_display == 'none' else self.pt_completer if not env.get('UPDATE_PROMPT_ON_KEYPRESS'): prompt_tokens_cached = self.prompt_tokens(None) get_prompt_tokens = lambda cli: prompt_tokens_cached rprompt_tokens_cached = self.rprompt_tokens(None) get_rprompt_tokens = lambda cli: rprompt_tokens_cached bottom_toolbar_tokens_cached = self.bottom_toolbar_tokens(None) get_bottom_toolbar_tokens = lambda cli: bottom_toolbar_tokens_cached else: get_prompt_tokens = self.prompt_tokens get_rprompt_tokens = self.rprompt_tokens get_bottom_toolbar_tokens = self.bottom_toolbar_tokens with self.prompter: prompt_args = { 'mouse_support': mouse_support, 'auto_suggest': auto_suggest, 'get_prompt_tokens': get_prompt_tokens, 'get_rprompt_tokens': get_rprompt_tokens, 'get_bottom_toolbar_tokens': get_bottom_toolbar_tokens, 'completer': completer, 'multiline': multiline, 'get_continuation_tokens': self.continuation_tokens, 'history': history, 'enable_history_search': enable_history_search, 'reserve_space_for_menu': 0, 'key_bindings_registry': self.key_bindings_manager.registry, 'display_completions_in_columns': multicolumn, 'complete_while_typing': complete_while_typing, } if builtins.__xonsh_env__.get('COLOR_INPUT'): if HAS_PYGMENTS: prompt_args['lexer'] = PygmentsLexer(pyghooks.XonshLexer) prompt_args['style'] = PygmentsStyle(pyghooks.xonsh_style_proxy(self.styler)) else: prompt_args['style'] = style_from_dict(DEFAULT_STYLE_DICT) line = self.prompter.prompt(**prompt_args) events.on_post_prompt.fire() return line
def singleline( self, auto_suggest=None, enable_history_search=True, multiline=True, **kwargs ): """Reads a single line of input from the shell. The store_in_history kwarg flags whether the input should be stored in PTK's in-memory history. """ events.on_pre_prompt.fire() env = builtins.__xonsh__.env mouse_support = env.get("MOUSE_SUPPORT") auto_suggest = auto_suggest if env.get("AUTO_SUGGEST") else None completions_display = env.get("COMPLETIONS_DISPLAY") complete_style = self.completion_displays_to_styles[completions_display] complete_while_typing = env.get("UPDATE_COMPLETIONS_ON_KEYPRESS") if complete_while_typing: # PTK requires history search to be none when completing while typing enable_history_search = False if HAS_PYGMENTS: self.styler.style_name = env.get("XONSH_COLOR_STYLE") completer = None if completions_display == "none" else self.pt_completer if env.get("UPDATE_PROMPT_ON_KEYPRESS"): get_prompt_tokens = self.prompt_tokens get_rprompt_tokens = self.rprompt_tokens get_bottom_toolbar_tokens = self.bottom_toolbar_tokens else: get_prompt_tokens = self.prompt_tokens() get_rprompt_tokens = self.rprompt_tokens() get_bottom_toolbar_tokens = self.bottom_toolbar_tokens() if env.get("VI_MODE"): editing_mode = EditingMode.VI else: editing_mode = EditingMode.EMACS if env.get("XONSH_HISTORY_MATCH_ANYWHERE"): self.prompter.default_buffer._history_matches = MethodType( _cust_history_matches, self.prompter.default_buffer ) elif ( self.prompter.default_buffer._history_matches is not self._history_matches_orig ): self.prompter.default_buffer._history_matches = self._history_matches_orig prompt_args = { "mouse_support": mouse_support, "auto_suggest": auto_suggest, "message": get_prompt_tokens, "rprompt": get_rprompt_tokens, "bottom_toolbar": get_bottom_toolbar_tokens, "completer": completer, "multiline": multiline, "editing_mode": editing_mode, "prompt_continuation": self.continuation_tokens, "enable_history_search": enable_history_search, "reserve_space_for_menu": 0, "key_bindings": self.key_bindings, "complete_style": complete_style, "complete_while_typing": complete_while_typing, "include_default_pygments_style": False, } if builtins.__xonsh__.env.get("COLOR_INPUT"): if HAS_PYGMENTS: prompt_args["lexer"] = PygmentsLexer(pyghooks.XonshLexer) style = style_from_pygments_cls(pyghooks.xonsh_style_proxy(self.styler)) else: style = style_from_pygments_dict(DEFAULT_STYLE_DICT) prompt_args["style"] = style style_overrides_env = env.get("PTK_STYLE_OVERRIDES") if style_overrides_env: try: style_overrides = Style.from_dict(style_overrides_env) prompt_args["style"] = merge_styles([style, style_overrides]) except (AttributeError, TypeError, ValueError): print_exception() line = self.prompter.prompt(**prompt_args) events.on_post_prompt.fire() return line
def singleline(self, auto_suggest=None, enable_history_search=True, multiline=True, **kwargs): """Reads a single line of input from the shell. The store_in_history kwarg flags whether the input should be stored in PTK's in-memory history. """ events.on_pre_prompt.fire() env = builtins.__xonsh_env__ mouse_support = env.get('MOUSE_SUPPORT') auto_suggest = auto_suggest if env.get('AUTO_SUGGEST') else None completions_display = env.get('COMPLETIONS_DISPLAY') if completions_display == 'multi': complete_style = CompleteStyle.MULTI_COLUMN complete_while_typing = env.get('UPDATE_COMPLETIONS_ON_KEYPRESS') if complete_while_typing: # PTK requires history search to be none when completing while typing enable_history_search = False if HAS_PYGMENTS: self.styler.style_name = env.get('XONSH_COLOR_STYLE') completer = None if completions_display == 'none' else self.pt_completer if env.get('UPDATE_PROMPT_ON_KEYPRESS'): get_prompt_tokens = self.prompt_tokens get_rprompt_tokens = self.rprompt_tokens get_bottom_toolbar_tokens = self.bottom_toolbar_tokens else: get_prompt_tokens = self.prompt_tokens() get_rprompt_tokens = self.rprompt_tokens() get_bottom_toolbar_tokens = self.bottom_toolbar_tokens() if env.get('VI_MODE'): editing_mode = EditingMode.VI else: editing_mode = EditingMode.EMACS prompt_args = { 'mouse_support': mouse_support, 'auto_suggest': auto_suggest, 'message': get_prompt_tokens, 'rprompt': get_rprompt_tokens, 'bottom_toolbar': get_bottom_toolbar_tokens, 'completer': completer, 'multiline': multiline, 'editing_mode': editing_mode, 'prompt_continuation': self.continuation_tokens, 'enable_history_search': enable_history_search, 'reserve_space_for_menu': 0, 'key_bindings': self.key_bindings, 'complete_style': complete_style, 'complete_while_typing': complete_while_typing, 'include_default_pygments_style': False, } if builtins.__xonsh_env__.get('COLOR_INPUT'): if HAS_PYGMENTS: prompt_args['lexer'] = PygmentsLexer(pyghooks.XonshLexer) style = style_from_pygments_cls( pyghooks.xonsh_style_proxy(self.styler)) else: style = style_from_pygments_dict(DEFAULT_STYLE_DICT) prompt_args['style'] = style line = self.prompter.prompt(**prompt_args) events.on_post_prompt.fire() return line
def singleline(self, store_in_history=True, auto_suggest=None, enable_history_search=True, multiline=True, **kwargs): """Reads a single line of input from the shell. The store_in_history kwarg flags whether the input should be stored in PTK's in-memory history. """ events.on_pre_prompt.fire() env = builtins.__xonsh_env__ mouse_support = env.get('MOUSE_SUPPORT') if store_in_history: history = self.history else: history = None enable_history_search = False auto_suggest = auto_suggest if env.get('AUTO_SUGGEST') else None completions_display = env.get('COMPLETIONS_DISPLAY') multicolumn = (completions_display == 'multi') complete_while_typing = env.get('UPDATE_COMPLETIONS_ON_KEYPRESS') if complete_while_typing: # PTK requires history search to be none when completing while typing enable_history_search = False if HAS_PYGMENTS: self.styler.style_name = env.get('XONSH_COLOR_STYLE') completer = None if completions_display == 'none' else self.pt_completer if not env.get('UPDATE_PROMPT_ON_KEYPRESS'): prompt_tokens_cached = self.prompt_tokens(None) get_prompt_tokens = lambda cli: prompt_tokens_cached rprompt_tokens_cached = self.rprompt_tokens(None) get_rprompt_tokens = lambda cli: rprompt_tokens_cached bottom_toolbar_tokens_cached = self.bottom_toolbar_tokens(None) get_bottom_toolbar_tokens = lambda cli: bottom_toolbar_tokens_cached else: get_prompt_tokens = self.prompt_tokens get_rprompt_tokens = self.rprompt_tokens get_bottom_toolbar_tokens = self.bottom_toolbar_tokens with self.prompter: prompt_args = { 'mouse_support': mouse_support, 'auto_suggest': auto_suggest, 'get_prompt_tokens': get_prompt_tokens, 'get_rprompt_tokens': get_rprompt_tokens, 'get_bottom_toolbar_tokens': get_bottom_toolbar_tokens, 'completer': completer, 'multiline': multiline, 'get_continuation_tokens': self.continuation_tokens, 'history': history, 'enable_history_search': enable_history_search, 'reserve_space_for_menu': 0, 'key_bindings_registry': self.key_bindings_manager.registry, 'display_completions_in_columns': multicolumn, 'complete_while_typing': complete_while_typing, } if builtins.__xonsh_env__.get('COLOR_INPUT'): if HAS_PYGMENTS: prompt_args['lexer'] = PygmentsLexer(pyghooks.XonshLexer) prompt_args['style'] = PygmentsStyle(pyghooks.xonsh_style_proxy(self.styler)) else: prompt_args['style'] = style_from_dict(DEFAULT_STYLE_DICT) line = self.prompter.prompt(**prompt_args) events.on_post_prompt.fire() return line
def singleline( self, auto_suggest=None, enable_history_search=True, multiline=True, **kwargs ): """Reads a single line of input from the shell. The store_in_history kwarg flags whether the input should be stored in PTK's in-memory history. """ events.on_pre_prompt.fire() env = builtins.__xonsh__.env mouse_support = env.get("MOUSE_SUPPORT") auto_suggest = auto_suggest if env.get("AUTO_SUGGEST") else None completions_display = env.get("COMPLETIONS_DISPLAY") complete_style = self.completion_displays_to_styles[completions_display] complete_while_typing = env.get("UPDATE_COMPLETIONS_ON_KEYPRESS") if complete_while_typing: # PTK requires history search to be none when completing while typing enable_history_search = False if HAS_PYGMENTS: self.styler.style_name = env.get("XONSH_COLOR_STYLE") completer = None if completions_display == "none" else self.pt_completer if env.get("UPDATE_PROMPT_ON_KEYPRESS"): get_prompt_tokens = self.prompt_tokens get_rprompt_tokens = self.rprompt_tokens get_bottom_toolbar_tokens = self.bottom_toolbar_tokens else: get_prompt_tokens = self.prompt_tokens() get_rprompt_tokens = self.rprompt_tokens() get_bottom_toolbar_tokens = self.bottom_toolbar_tokens() if env.get("VI_MODE"): editing_mode = EditingMode.VI else: editing_mode = EditingMode.EMACS if env.get("XONSH_HISTORY_MATCH_ANYWHERE"): self.prompter.default_buffer._history_matches = MethodType( _cust_history_matches, self.prompter.default_buffer ) elif ( self.prompter.default_buffer._history_matches is not self._history_matches_orig ): self.prompter.default_buffer._history_matches = self._history_matches_orig prompt_args = { "mouse_support": mouse_support, "auto_suggest": auto_suggest, "message": get_prompt_tokens, "rprompt": get_rprompt_tokens, "bottom_toolbar": get_bottom_toolbar_tokens, "completer": completer, "multiline": multiline, "editing_mode": editing_mode, "prompt_continuation": self.continuation_tokens, "enable_history_search": enable_history_search, "reserve_space_for_menu": 0, "key_bindings": self.key_bindings, "complete_style": complete_style, "complete_while_typing": complete_while_typing, "include_default_pygments_style": False, } if builtins.__xonsh__.env.get("COLOR_INPUT"): if HAS_PYGMENTS: prompt_args["lexer"] = PygmentsLexer(pyghooks.XonshLexer) style = style_from_pygments_cls(pyghooks.xonsh_style_proxy(self.styler)) else: style = style_from_pygments_dict(DEFAULT_STYLE_DICT) prompt_args["style"] = style line = self.prompter.prompt(**prompt_args) events.on_post_prompt.fire() return line
def singleline(self, auto_suggest=None, enable_history_search=True, multiline=True, **kwargs): """Reads a single line of input from the shell. The store_in_history kwarg flags whether the input should be stored in PTK's in-memory history. """ events.on_pre_prompt_format.fire() env = builtins.__xonsh__.env mouse_support = env.get("MOUSE_SUPPORT") auto_suggest = auto_suggest if env.get("AUTO_SUGGEST") else None refresh_interval = env.get("PROMPT_REFRESH_INTERVAL") refresh_interval = refresh_interval if refresh_interval > 0 else None complete_in_thread = env.get("COMPLETION_IN_THREAD") completions_display = env.get("COMPLETIONS_DISPLAY") complete_style = self.completion_displays_to_styles[ completions_display] complete_while_typing = env.get("UPDATE_COMPLETIONS_ON_KEYPRESS") if complete_while_typing: # PTK requires history search to be none when completing while typing enable_history_search = False if HAS_PYGMENTS: self.styler.style_name = env.get("XONSH_COLOR_STYLE") completer = None if completions_display == "none" else self.pt_completer events.on_timingprobe.fire(name="on_pre_prompt_tokenize") get_bottom_toolbar_tokens = self.bottom_toolbar_tokens if env.get("UPDATE_PROMPT_ON_KEYPRESS"): get_prompt_tokens = self.prompt_tokens get_rprompt_tokens = self.rprompt_tokens else: get_prompt_tokens = self.prompt_tokens() get_rprompt_tokens = self.rprompt_tokens() if get_bottom_toolbar_tokens: get_bottom_toolbar_tokens = get_bottom_toolbar_tokens() events.on_timingprobe.fire(name="on_post_prompt_tokenize") if env.get("VI_MODE"): editing_mode = EditingMode.VI else: editing_mode = EditingMode.EMACS if env.get("XONSH_HISTORY_MATCH_ANYWHERE"): self.prompter.default_buffer._history_matches = MethodType( _cust_history_matches, self.prompter.default_buffer) elif (self.prompter.default_buffer._history_matches is not self._history_matches_orig): self.prompter.default_buffer._history_matches = self._history_matches_orig prompt_args = { "mouse_support": mouse_support, "auto_suggest": auto_suggest, "message": get_prompt_tokens, "rprompt": get_rprompt_tokens, "bottom_toolbar": get_bottom_toolbar_tokens, "completer": completer, "multiline": multiline, "editing_mode": editing_mode, "prompt_continuation": self.continuation_tokens, "enable_history_search": enable_history_search, "reserve_space_for_menu": 0, "key_bindings": self.key_bindings, "complete_style": complete_style, "complete_while_typing": complete_while_typing, "include_default_pygments_style": False, "refresh_interval": refresh_interval, "complete_in_thread": complete_in_thread, } if env.get("COLOR_INPUT"): events.on_timingprobe.fire(name="on_pre_prompt_style") if HAS_PYGMENTS: prompt_args["lexer"] = PygmentsLexer(pyghooks.XonshLexer) style = style_from_pygments_cls( pyghooks.xonsh_style_proxy(self.styler)) else: style = style_from_pygments_dict(DEFAULT_STYLE_DICT) prompt_args["style"] = style events.on_timingprobe.fire(name="on_post_prompt_style") style_overrides_env = env.get("PTK_STYLE_OVERRIDES") if style_overrides_env: try: style_overrides = Style.from_dict(style_overrides_env) prompt_args["style"] = merge_styles( [style, style_overrides]) except (AttributeError, TypeError, ValueError): print_exception() if env["ENABLE_ASYNC_PROMPT"]: # once the prompt is done, update it in background as each future is completed prompt_args["pre_run"] = self.prompt_formatter.start_update events.on_pre_prompt.fire() line = self.prompter.prompt(**prompt_args) events.on_post_prompt.fire() return line