mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
#3840 fallback for print_color
if shell is not yet initialized
This commit is contained in:
parent
4da940c036
commit
487f15aed3
1 changed files with 13 additions and 2 deletions
|
@ -1837,7 +1837,14 @@ def format_color(string, **kwargs):
|
|||
shell instances method of the same name. The results of this function should
|
||||
be directly usable by print_color().
|
||||
"""
|
||||
return builtins.__xonsh__.shell.shell.format_color(string, **kwargs)
|
||||
try:
|
||||
return builtins.__xonsh__.shell.shell.format_color(string, **kwargs)
|
||||
except AttributeError:
|
||||
# fallback for ANSI if shell is not yet initialized
|
||||
from xonsh.ansi_colors import ansi_partial_color_format
|
||||
|
||||
style = builtins.__xonsh__.env.get("XONSH_COLOR_STYLE")
|
||||
return ansi_partial_color_format(string, style=style)
|
||||
|
||||
|
||||
def print_color(string, **kwargs):
|
||||
|
@ -1845,7 +1852,11 @@ def print_color(string, **kwargs):
|
|||
method of the same name. Colors will be formatted if they have not already
|
||||
been.
|
||||
"""
|
||||
builtins.__xonsh__.shell.shell.print_color(string, **kwargs)
|
||||
try:
|
||||
builtins.__xonsh__.shell.shell.print_color(string, **kwargs)
|
||||
except AttributeError:
|
||||
# fallback for ANSI if shell is not yet initialized
|
||||
print(format_color(string, **kwargs))
|
||||
|
||||
|
||||
def color_style_names():
|
||||
|
|
Loading…
Add table
Reference in a new issue