mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
Merge pull request #3817 from anki-code/printx
Added printx to builtins
This commit is contained in:
commit
68993e4b3d
4 changed files with 34 additions and 2 deletions
|
@ -54,6 +54,9 @@ line is ``#!/usr/bin/env xonsh``.
|
||||||
- ``v=$(echo 1)``
|
- ``v=$(echo 1)``
|
||||||
- In bash, backticks mean to run a captured subprocess - it's ``$()`` in xonsh. Backticks in xonsh
|
- In bash, backticks mean to run a captured subprocess - it's ``$()`` in xonsh. Backticks in xonsh
|
||||||
mean regex globbing (i.e. ``ls `/etc/pass.*```).
|
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``
|
* - ``shopt -s dotglob``
|
||||||
- ``$DOTGLOB = True``
|
- ``$DOTGLOB = True``
|
||||||
- Globbing files with ``*`` or ``**`` will also match dotfiles, or those ‘hidden’ files whose names
|
- Globbing files with ``*`` or ``**`` will also match dotfiles, or those ‘hidden’ files whose names
|
||||||
|
|
|
@ -1536,8 +1536,8 @@ For example:
|
||||||
(env) >>>
|
(env) >>>
|
||||||
|
|
||||||
|
|
||||||
You can also color your prompt easily by inserting keywords such as ``{GREEN}``
|
You can also color your prompt (or print colored messages using ``print_color`` function) easily by inserting
|
||||||
or ``{BOLD_BLUE}``. Colors have the form shown below:
|
keywords such as ``{GREEN}`` or ``{BOLD_BLUE}``. Colors have the form shown below:
|
||||||
|
|
||||||
* ``RESET``: Resets any previously used styling.
|
* ``RESET``: Resets any previously used styling.
|
||||||
* ``COLORNAME``: Inserts a color code for the following basic colors,
|
* ``COLORNAME``: Inserts a color code for the following basic colors,
|
||||||
|
|
23
news/printx.rst
Normal file
23
news/printx.rst
Normal 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>
|
|
@ -44,6 +44,7 @@ from xonsh.tools import (
|
||||||
globpath,
|
globpath,
|
||||||
XonshError,
|
XonshError,
|
||||||
XonshCalledProcessError,
|
XonshCalledProcessError,
|
||||||
|
print_color,
|
||||||
)
|
)
|
||||||
from xonsh.lazyimps import pty, termios, fcntl
|
from xonsh.lazyimps import pty, termios, fcntl
|
||||||
from xonsh.commands_cache import CommandsCache
|
from xonsh.commands_cache import CommandsCache
|
||||||
|
@ -1463,6 +1464,8 @@ class XonshSession:
|
||||||
"execx": "__xonsh__.builtins.execx",
|
"execx": "__xonsh__.builtins.execx",
|
||||||
"compilex": "__xonsh__.builtins.compilex",
|
"compilex": "__xonsh__.builtins.compilex",
|
||||||
"events": "__xonsh__.builtins.events",
|
"events": "__xonsh__.builtins.events",
|
||||||
|
"print_color": "__xonsh__.builtins.print_color",
|
||||||
|
"printx": "__xonsh__.builtins.printx",
|
||||||
}
|
}
|
||||||
for refname, objname in proxy_mapping.items():
|
for refname, objname in proxy_mapping.items():
|
||||||
proxy = DynamicAccessProxy(refname, objname)
|
proxy = DynamicAccessProxy(refname, objname)
|
||||||
|
@ -1485,6 +1488,8 @@ class XonshSession:
|
||||||
"compilex",
|
"compilex",
|
||||||
"default_aliases",
|
"default_aliases",
|
||||||
"events",
|
"events",
|
||||||
|
"print_color",
|
||||||
|
"printx",
|
||||||
]
|
]
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
|
@ -1501,6 +1506,7 @@ class _BuiltIns:
|
||||||
self.execx = None if execer is None else execer.exec
|
self.execx = None if execer is None else execer.exec
|
||||||
self.compilex = None if execer is None else execer.compile
|
self.compilex = None if execer is None else execer.compile
|
||||||
self.events = events
|
self.events = events
|
||||||
|
self.print_color = self.printx = print_color
|
||||||
|
|
||||||
|
|
||||||
class DynamicAccessProxy:
|
class DynamicAccessProxy:
|
||||||
|
|
Loading…
Add table
Reference in a new issue