Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
 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
Exemple #5
0
 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
Exemple #6
0
 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)
Exemple #7
0
 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)