Skip to content

Commit 06279f7

Browse files
committed
docs
1 parent 9a98dec commit 06279f7

File tree

9 files changed

+26
-30
lines changed

9 files changed

+26
-30
lines changed

docs/source/console.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The :meth:`~rich.console.Console.log` methods offers the same capabilities as pr
4444
<pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><span style="color: #7fbfbf">[16:32:08] </span>Hello, World! <span style="color: #7f7f7f">&lt;stdin&gt;:1</span>
4545
</pre>
4646

47-
To help with debugging, the log() method has a ``log_locals`` parameter. If you set this to ``True`` Rich will display a table of local variables where the method was called.
47+
To help with debugging, the log() method has a ``log_locals`` parameter. If you set this to ``True``, Rich will display a table of local variables where the method was called.
4848

4949

5050
Exporting

docs/source/markup.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ For strikethrough, wrap the text in tildes. e.g. ``~this has a line through it~`
2020
For code, wrap the text in backticks. e.g. ```import this```
2121

2222

23-
Styles
24-
------
23+
Styling
24+
-------
2525

2626
For other styles and color, you can use a syntax similar to 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]``.
2727

docs/source/reference/theme.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
rich.theme
2+
==========
3+
4+
.. automodule:: rich.theme
5+
:members: Theme
6+

docs/source/style.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ You can parse a style definition explicitly with the :meth:`~rich.style.Style.pa
6666
Style Themes
6767
------------
6868

69-
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 pre-define styles, so if you ever need to modify a style you only need change one file.
69+
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.
7070

71-
Style themes can also make your code more semantic, for instance a style called ``"warning"`` better expresses intent that ``"italic magenta underline"``.
71+
Style themes can make your code more semantic, for instance a style called ``"warning"`` better expresses intent that ``"italic magenta underline"``.
7272

7373
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::
7474

@@ -92,6 +92,6 @@ If you prefer you can write your styles in an external config file rather than i
9292
[styles]
9393
info = dim cyan
9494
warning = magenta
95-
danger bold red
95+
danger = bold red
9696

97-
You can read these files with the :method:`~rich.theme.Theme.read` method.
97+
You can read these files with the :meth:`~rich.theme.Theme.read` method.

docs/source/tables.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Tables
33

44
Rich's :class:`~rich.table.Table` class offers a variety ways of rendering tabular data to the terminal.
55

6-
To render a table, construct a :class:`~rich.table.Table` object, add data, then call :meth:`~rich.console.Console.print` or :meth:`~rich.console.Console.log` to write it to the console.
6+
To render a table, construct a :class:`~rich.table.Table` object, add columns with :meth:`~rich.table.Table.add_column`, and rows with :meth:`~rich.table.Table.add_row` -- then print it to the console.
77

88
Here's an example::
99

docs/source/text.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Rich Text
33

44
Rich has a :class:`~rich.text.Text` class for text that may be marked up with color and style attributes. You can consider this class to be like a mutable string with style information. The methods on the Text() instance are similar to a Python ``str`` but are designed to preserve any style information.
55

6-
One way to add a style to Text is the :meth:`~tich.text.Text.styleize` method which applies a style to a start and end offset. Here is an example::
6+
One way to add a style to Text is the :meth:`~tich.text.Text.stylize` method which applies a style to a start and end offset. Here is an example::
77

88
from rich.text import Text
99
text = Text("Hello, World!")
10-
text.styleize(0, 6, "bold magenta")
10+
text.stylize(0, 6, "bold magenta")
1111
console.print(text)
1212

1313
This will print "Hello, World!" to the terminal, with the first word in bold magenta.

rich/console.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,6 @@ def _collect_renderables(
719719
Returns:
720720
List[ConsoleRenderable]: A list of things to render.
721721
"""
722-
from .text import Text
723-
724722
sep_text = Text(sep, end=end)
725723
renderables: List[ConsoleRenderable] = []
726724
append = renderables.append
@@ -753,7 +751,7 @@ def check_text() -> None:
753751
check_text()
754752
append(Pretty(renderable, highlighter=_highlighter))
755753
else:
756-
append_text(_highlighter(repr(renderable)))
754+
append_text(_highlighter(str(renderable)))
757755

758756
check_text()
759757
return renderables
@@ -788,7 +786,6 @@ def print(
788786
r"""Print to the console.
789787
790788
Args:
791-
792789
objects (positional args): Objects to log to the terminal.
793790
sep (str, optional): String to write between print data. Defaults to " ".
794791
end (str, optional): String to write at end of print data. Defaults to "\n".

rich/table.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from .console import (
2020
Console,
2121
ConsoleOptions,
22-
ConsoleRenderable,
2322
JustifyValues,
2423
RenderableType,
2524
RenderResult,
@@ -147,8 +146,8 @@ def padding(self, padding: PaddingDimensions) -> "Table":
147146

148147
def add_column(
149148
self,
150-
header: Union[str, "ConsoleRenderable"] = "",
151-
footer: Union[str, "ConsoleRenderable"] = "",
149+
header: "RenderableType" = "",
150+
footer: "RenderableType" = "",
152151
header_style: Union[str, Style] = None,
153152
footer_style: Union[str, Style] = None,
154153
style: Union[str, Style] = None,
@@ -160,9 +159,9 @@ def add_column(
160159
"""Add a column to the table.
161160
162161
Args:
163-
header (Union[str, ConsoleRenderable], optional): Text or renderable for the header.
162+
header (RenderableType, optional): Text or renderable for the header.
164163
Defaults to "".
165-
footer (Union[str, ConsoleRenderable], optional): Text or renderable for the footer.
164+
footer (RenderableType, optional): Text or renderable for the footer.
166165
Defaults to "".
167166
header_style (Union[str, Style], optional): Style for the header. Defaults to "none".
168167
footer_style (Union[str, Style], optional): Style for the header. Defaults to "none".
@@ -196,7 +195,6 @@ def add_row(self, *renderables: Optional["RenderableType"]) -> None:
196195
Raises:
197196
errors.NotRenderableError: If you add something that can't be rendered.
198197
"""
199-
from .console import ConsoleRenderable
200198

201199
def add_cell(column: Column, renderable: "RenderableType") -> None:
202200
column._cells.append(renderable)
@@ -456,7 +454,7 @@ def _render(
456454
from .console import Console
457455
from . import box
458456

459-
c = Console(markup=False)
457+
c = Console(markup=True)
460458
table = Table(
461459
Column(
462460
"Foo", footer=Text("Total", justify="right"), footer_style="bold", ratio=1

rich/theme.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,16 @@ class Theme:
1414
"""
1515

1616
def __init__(self, styles: Dict[str, Style] = None, inherit: bool = True):
17-
if inherit:
18-
self.styles = DEFAULT_STYLES.copy()
19-
else:
20-
self.styles = {}
17+
self.styles = DEFAULT_STYLES.copy() if inherit else {}
2118
if styles is not None:
2219
self.styles.update(styles)
2320

2421
@property
2522
def config(self) -> str:
2623
"""Get contents of a config file for this theme."""
27-
config_lines = ["[styles]"]
28-
append = config_lines.append
29-
for name, style in sorted(self.styles.items()):
30-
append(f"{name} = {style}")
31-
config = "\n".join(config_lines)
24+
config = "[styles]\n" + "\n".join(
25+
f"{name} = {style}" for name, style in sorted(self.styles.items())
26+
)
3227
return config
3328

3429
@classmethod

0 commit comments

Comments
 (0)