mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-06 09:20:57 +01:00
some translations
This commit is contained in:
parent
50101ce9a7
commit
c111811bab
2 changed files with 40 additions and 12 deletions
|
@ -125,9 +125,17 @@ def ansi_reverse_style(style='default', return_style=False):
|
||||||
# add keys to make this more useful
|
# add keys to make this more useful
|
||||||
updates = {
|
updates = {
|
||||||
'1': 'BOLD_',
|
'1': 'BOLD_',
|
||||||
|
'2': 'FAINT_',
|
||||||
'4': 'UNDERLINE_',
|
'4': 'UNDERLINE_',
|
||||||
|
'5': 'SLOWBLINK_',
|
||||||
'1;4': 'BOLD_UNDERLINE_',
|
'1;4': 'BOLD_UNDERLINE_',
|
||||||
'4;1': 'BOLD_UNDERLINE_',
|
'4;1': 'BOLD_UNDERLINE_',
|
||||||
|
'38': 'SET_FOREGROUND_',
|
||||||
|
'48': 'SET_BACKGROUND_',
|
||||||
|
'38;2': 'SET_FOREGROUND_RGB_',
|
||||||
|
'48;2': 'SET_BACKGROUND_RGB_',
|
||||||
|
'38;5': 'SET_FOREGROUND_SHORT_',
|
||||||
|
'48;5': 'SET_BACKGROUND_SHORT_',
|
||||||
}
|
}
|
||||||
for ec, name in reversed_style.items():
|
for ec, name in reversed_style.items():
|
||||||
no_left_zero = ec.lstrip('0')
|
no_left_zero = ec.lstrip('0')
|
||||||
|
@ -148,6 +156,17 @@ def ANSI_ESCAPE_CODE_RE():
|
||||||
return re.compile(r'\001?(\033\[)?([0-9;]+)m?\002?')
|
return re.compile(r'\001?(\033\[)?([0-9;]+)m?\002?')
|
||||||
|
|
||||||
|
|
||||||
|
@lazyobject
|
||||||
|
def ANSI_REVERSE_COLOR_NAME_TRANSLATIONS():
|
||||||
|
return {
|
||||||
|
'UNDERLINE_BOLD_': 'BOLD_UNDERLINE_',
|
||||||
|
'SET_FOREGROUND_FAINT_': 'SET_FOREGROUND_RGB_',
|
||||||
|
'SET_FOREGROUND_FAINT_': 'SET_FOREGROUND_RGB_',
|
||||||
|
'SET_FOREGROUND_SLOWBLINK_': 'SET_FOREGROUND_SHORT_',
|
||||||
|
'SET_BACKGROUND_SLOWBLINK_': 'SET_BACKGROUND_SHORT_',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def ansi_color_escape_code_to_name(escape_code, style='default', reversed_style=None):
|
def ansi_color_escape_code_to_name(escape_code, style='default', reversed_style=None):
|
||||||
"""Converts an ASNI color code escape sequence to a tuple of color names
|
"""Converts an ASNI color code escape sequence to a tuple of color names
|
||||||
in the provided style ('default', by default). For example,
|
in the provided style ('default', by default). For example,
|
||||||
|
@ -170,8 +189,7 @@ def ansi_color_escape_code_to_name(escape_code, style='default', reversed_style=
|
||||||
# skip '0' entries
|
# skip '0' entries
|
||||||
continue
|
continue
|
||||||
n = n + name if n else name
|
n = n + name if n else name
|
||||||
if n == 'UNDERLINE_BOLD_':
|
n = ANSI_REVERSE_COLOR_NAME_TRANSLATIONS.get(n, n)
|
||||||
n = 'BOLD_UNDERLINE_'
|
|
||||||
if n.endswith('_'):
|
if n.endswith('_'):
|
||||||
continue
|
continue
|
||||||
norm_names.append(n)
|
norm_names.append(n)
|
||||||
|
|
|
@ -1297,22 +1297,19 @@ class Env(cabc.MutableMapping):
|
||||||
self._d["PATH"] = list(PATH_DEFAULT)
|
self._d["PATH"] = list(PATH_DEFAULT)
|
||||||
self._detyped = None
|
self._detyped = None
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def detypeable(val):
|
|
||||||
return not (callable(val) or isinstance(val, cabc.MutableMapping))
|
|
||||||
|
|
||||||
def detype(self):
|
def detype(self):
|
||||||
if self._detyped is not None:
|
if self._detyped is not None:
|
||||||
return self._detyped
|
return self._detyped
|
||||||
ctx = {}
|
ctx = {}
|
||||||
for key, val in self._d.items():
|
for key, val in self._d.items():
|
||||||
if key not in self._ensurers and not self.detypeable(val):
|
|
||||||
continue
|
|
||||||
if not isinstance(key, str):
|
if not isinstance(key, str):
|
||||||
key = str(key)
|
key = str(key)
|
||||||
ensurer = self.get_ensurer(key)
|
ensurer = self.get_ensurer(key)
|
||||||
val = ensurer.detype(val)
|
if not ensurer.detype or not callable(ensurer.detype):
|
||||||
ctx[key] = val
|
# cannot actually detype this var.
|
||||||
|
continue
|
||||||
|
deval = ensurer.detype(val)
|
||||||
|
ctx[key] = deval
|
||||||
self._detyped = ctx
|
self._detyped = ctx
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
@ -1334,7 +1331,20 @@ class Env(cabc.MutableMapping):
|
||||||
os_environ.update(self._orig_env)
|
os_environ.update(self._orig_env)
|
||||||
self._orig_env = None
|
self._orig_env = None
|
||||||
|
|
||||||
def get_ensurer(self, key, default=Ensurer(always_true, None, ensure_string)):
|
@staticmethod
|
||||||
|
def detypeable(val):
|
||||||
|
return not (callable(val) or isinstance(val, cabc.MutableMapping))
|
||||||
|
|
||||||
|
def _get_default_ensurer(self, val, default=None):
|
||||||
|
if default is not None:
|
||||||
|
return default
|
||||||
|
if self.detypeable(val):
|
||||||
|
default = Ensurer(always_true, None, ensure_string)
|
||||||
|
else:
|
||||||
|
default = Ensurer(always_true, None, False)
|
||||||
|
return default
|
||||||
|
|
||||||
|
def get_ensurer(self, key, val=None, default=None):
|
||||||
"""Gets an ensurer for the given key."""
|
"""Gets an ensurer for the given key."""
|
||||||
if key in self._ensurers:
|
if key in self._ensurers:
|
||||||
return self._ensurers[key]
|
return self._ensurers[key]
|
||||||
|
@ -1344,7 +1354,7 @@ class Env(cabc.MutableMapping):
|
||||||
if k.match(key) is not None:
|
if k.match(key) is not None:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
ensurer = default
|
ensurer = self._get_default_ensurer(val=val, default=default)
|
||||||
self._ensurers[key] = ensurer
|
self._ensurers[key] = ensurer
|
||||||
return ensurer
|
return ensurer
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue