mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 01:58:24 +00:00
add attributes
This commit is contained in:
parent
5097f44092
commit
afb94d97dc
13 changed files with 251 additions and 709 deletions
|
@ -9,7 +9,7 @@ Rich supports a simple markup which you can use to insert color and styles virtu
|
|||
Syntax
|
||||
------
|
||||
|
||||
Console markup uses a syntax inspired by `bbcode <https://en.wikipedia.org/wiki/BBCode>`_. If you write the style (see :ref:`styles`) in square brackets, i.e. ``[bold red]``, that style will apply until it is *closed* with a corresponding ``[/bold red]``.
|
||||
Console markup uses a syntax inspired by `bbcode <https://en.wikipedia.org/wiki/BBCode>`_. If you write the style (see :ref:`styles`) in square brackets, e.g. ``[bold red]``, that style will apply until it is *closed* with a corresponding ``[/bold red]``.
|
||||
|
||||
Here's a simple example::
|
||||
|
||||
|
|
|
@ -40,12 +40,20 @@ You can set a style attribute by adding one or more of the following words:
|
|||
|
||||
* ``"bold"`` or ``"b"`` for bold text.
|
||||
* ``"blink"`` for text that flashes (use this one sparingly).
|
||||
* ``"conceal"`` for *concealed* text (not supported by many terminals).
|
||||
* ``"blink2"`` for text that flashes rapidly (not supported by most terminals).
|
||||
* ``"conceal"`` for *concealed* text (not supported by most terminals).
|
||||
* ``"italic"`` or ``"i"`` for italic text.
|
||||
* ``"reverse"`` or ``"r"`` for text with foreground and background colors reversed.
|
||||
* ``"strike"`` or ``"s"`` for text with a line through it.
|
||||
* ``"underline"`` or ``"u"`` for underlined text.
|
||||
|
||||
Rich also supports the following styles, which are not well supported and may not display in your terminal:
|
||||
|
||||
* ``"underline2"`` or ``"uu"`` for doubly underlined text.
|
||||
* ``"frame"`` for framed text.
|
||||
* ``"encircle"`` for encircled text.
|
||||
* ``"overline"`` or ``"o"`` for overlined text.
|
||||
|
||||
Style attributes and colors may be used in combination with each other. For example::
|
||||
|
||||
console.print("Danger, Will Robinson!", style="blink bold red underline on white")
|
||||
|
@ -86,11 +94,11 @@ You can parse a style definition explicitly with the :meth:`~rich.style.Style.pa
|
|||
Style Themes
|
||||
------------
|
||||
|
||||
If you re-use styles it can be a maintenance headache if you ever want to modify an attribute or color -- you would have to change every line where the style is used. Rich provides a :class:`rich.theme.Theme` class which you can use to define custom styles that you can refer to by name. That way you only need update your styles in one place.
|
||||
If you re-use styles it can be a maintenance headache if you ever want to modify an attribute or color -- you would have to change every line where the style is used. Rich provides a :class:`~rich.theme.Theme` class which you can use to define custom styles that you can refer to by name. That way you only need update your styles in one place.
|
||||
|
||||
Style themes can make your code more semantic, for instance a style called ``"warning"`` better expresses intent that ``"italic magenta underline"``.
|
||||
|
||||
To use a style theme, construct a :class:`rich.theme.Theme` instance and pass it to the :class:`~rich.console.Console` constructor. Here's an example::
|
||||
To use a style theme, construct a :class:`~rich.theme.Theme` instance and pass it to the :class:`~rich.console.Console` constructor. Here's an example::
|
||||
|
||||
from rich.console import Console
|
||||
from rich.theme import Theme
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue