Merge pull request #3817 from anki-code/printx

Added printx to builtins
This commit is contained in:
Anthony Scopatz 2020-10-06 15:25:20 -05:00 committed by GitHub
commit 68993e4b3d
Failed to generate hash of commit
4 changed files with 34 additions and 2 deletions

View file

@ -54,6 +54,9 @@ line is ``#!/usr/bin/env xonsh``.
- ``v=$(echo 1)``
- In bash, backticks mean to run a captured subprocess - it's ``$()`` in xonsh. Backticks in xonsh
mean regex globbing (i.e. ``ls `/etc/pass.*```).
* - ``echo -e "\033[0;31mRed text\033[0m"``
- ``printx("{RED}Red text{RESET}")``
- Print colored text as easy as possible.
* - ``shopt -s dotglob``
- ``$DOTGLOB = True``
- Globbing files with ``*`` or ``**`` will also match dotfiles, or those hidden files whose names

View file

@ -1536,8 +1536,8 @@ For example:
(env) >>>
You can also color your prompt easily by inserting keywords such as ``{GREEN}``
or ``{BOLD_BLUE}``. Colors have the form shown below:
You can also color your prompt (or print colored messages using ``print_color`` function) easily by inserting
keywords such as ``{GREEN}`` or ``{BOLD_BLUE}``. Colors have the form shown below:
* ``RESET``: Resets any previously used styling.
* ``COLORNAME``: Inserts a color code for the following basic colors,

23
news/printx.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* Added ``print_color`` and ``printx`` functions to builtins as reference to ``xonsh.tools.print_color``.
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -44,6 +44,7 @@ from xonsh.tools import (
globpath,
XonshError,
XonshCalledProcessError,
print_color,
)
from xonsh.lazyimps import pty, termios, fcntl
from xonsh.commands_cache import CommandsCache
@ -1463,6 +1464,8 @@ class XonshSession:
"execx": "__xonsh__.builtins.execx",
"compilex": "__xonsh__.builtins.compilex",
"events": "__xonsh__.builtins.events",
"print_color": "__xonsh__.builtins.print_color",
"printx": "__xonsh__.builtins.printx",
}
for refname, objname in proxy_mapping.items():
proxy = DynamicAccessProxy(refname, objname)
@ -1485,6 +1488,8 @@ class XonshSession:
"compilex",
"default_aliases",
"events",
"print_color",
"printx",
]
for name in names:
@ -1501,6 +1506,7 @@ class _BuiltIns:
self.execx = None if execer is None else execer.exec
self.compilex = None if execer is None else execer.compile
self.events = events
self.print_color = self.printx = print_color
class DynamicAccessProxy: