changelog

This commit is contained in:
Will McGugan 2020-10-09 15:36:17 +01:00
commit 31423ad5e9
11 changed files with 59 additions and 15 deletions

View File

@ -16,11 +16,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added legacy_windows to ConsoleOptions
- Added ascii_only to ConsoleOptions
- Addded box.SQUARE_DOUBLE_HEAD
- Added highlighting of EUI-48 and EUI-64 (MAC addresses)
### Changed
- Dropped box.get_safe_box function in favor of Box.substitute
### Fixed
- Fixed typo in `Style.transparent_background` method name.
## [8.0.0] - 2020-10-03
### Added

View File

@ -69,6 +69,11 @@ This allows you to specify the text of the column only. If you want to set other
title="Star Wars Movies"
)
Lines
~~~~~
By default, Tables will show a line under the header only. If you want to show lines between all rows add ``show_lines=True`` to the constructor.
Grids
~~~~~

View File

@ -3,7 +3,9 @@
Rich Text
=========
Rich has a :class:`~rich.text.Text` class you can use to mark up strings with color and style attributes. You can consider this class to be like a mutable string which also contains style information.
Rich has a :class:`~rich.text.Text` class you can use to mark up strings with color and style attributes. You can use a Text instance anywhere a string is accepted, which gives you a lot of control over presentation.
You can consider this class to be like a string with marked up regions of text. Unlike a builtin ``str``, a Text instance is mutable, and most methods operate in-place rather than returning a new instance.
One way to add a style to Text is the :meth:`~rich.text.Text.stylize` method which applies a style to a start and end offset. Here is an example::

View File

@ -630,7 +630,7 @@ class Console:
return ConsoleDimensions(80, 25)
width, height = shutil.get_terminal_size()
# get_terminal_size can report 0, 0 if run from psuedo-terminal
# get_terminal_size can report 0, 0 if run from pseudo-terminal
width = width or 80
height = height or 25
return ConsoleDimensions(
@ -759,7 +759,7 @@ class Console:
is required, such as the Panel class which draws a border around any renderable object.
Args:
renderables (Iterable[RenderableType]): Any object or objects renderable in the console.
renderable (RenderableType): Any object renderable in the console.
options (Optional[ConsoleOptions], optional): Console options, or None to use self.options. Default to ``None``.
style (Style, optional): Optional style to apply to renderables. Defaults to ``None``.
pad (bool, optional): Pad lines shorter than render width. Defaults to ``True``.
@ -868,7 +868,7 @@ class Console:
"""Combined a number of renderables and text in to one renderable.
Args:
renderables (Iterable[Union[str, ConsoleRenderable]]): Anything that Rich can render.
objects (Iterable[Any]): Anything that Rich can render.
sep (str, optional): String to write between print data. Defaults to " ".
end (str, optional): String to write at end of print data. Defaults to "\\n".
justify (str, optional): One of "left", "right", "center", or "full". Defaults to ``None``.
@ -1376,7 +1376,7 @@ class Console:
clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.
code_format (str, optional): Format string to render HTML, should contain {foreground}
{background} and {code}.
inline_styes (bool, optional): If ``True`` styles will be inlined in to spans, which makes files
inline_styles (bool, optional): If ``True`` styles will be inlined in to spans, which makes files
larger but easier to cut and paste markup. If ``False``, styles will be embedded in a style tag.
Defaults to False.

View File

@ -61,6 +61,8 @@ DEFAULT_STYLES: Dict[str, Style] = {
"repr.comma": Style(bold=True),
"repr.ipv4": Style(bold=True, color="bright_green"),
"repr.ipv6": Style(bold=True, color="bright_green"),
"repr.eui48": Style(bold=True, color="bright_green"),
"repr.eui64": Style(bold=True, color="bright_green"),
"repr.tag_start": Style(bold=True),
"repr.tag_name": Style(color="bright_magenta", bold=True),
"repr.tag_contents": Style(color="default"),

View File

@ -80,6 +80,12 @@ class ReprHighlighter(RegexHighlighter):
r"(?P<path>\B(\/[\w\.\-\_\+]+)*\/)(?P<filename>[\w\.\-\_\+]*)?",
r"(?P<ipv4>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})",
r"(?P<ipv6>([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4})",
r"(?P<eui48>([0-9A-Fa-f]{1,2}-){5}[0-9A-Fa-f]{1,2})", # EUI-48 6x2 hyphen
r"(?P<eui64>([0-9A-Fa-f]{1,2}-){7}[0-9A-Fa-f]{1,2})", # EUI-64 8x2 hyphen
r"(?P<eui48>([0-9A-Fa-f]{1,2}:){5}[0-9A-Fa-f]{1,2})", # EUI-48 6x2 colon
r"(?P<eui64>([0-9A-Fa-f]{1,2}:){7}[0-9A-Fa-f]{1,2})", # EUI-64 8x2 colon
r"(?P<eui48>([0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4})", # EUI-48 3x4 dot
r"(?P<eui64>([0-9A-Fa-f]{4}\.){3}[0-9A-Fa-f]{4})", # EUI-64 4x4 dot
r"(?<!\\)(?P<str>b?\'\'\'.*?(?<!\\)\'\'\'|b?\'.*?(?<!\\)\'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
r"(?P<url>https?:\/\/[0-9a-zA-Z\$\-\_\+\!`\(\)\,\.\?\/\;\:\&\=\%\#]*)",
r"(?P<uuid>[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12})",

View File

@ -359,7 +359,7 @@ def pretty_repr(
Args:
_object (Any): Object to repr.
max_width (int, optional): Diresired maximum width of repr string. Defaults to 80.
max_width (int, optional): Desired maximum width of repr string. Defaults to 80.
indent_size (int, optional): Number of spaces to indent. Defaults to 4.
expand_all (bool, optional): Expand all containers regardless of available width. Defaults to False.

View File

@ -345,7 +345,7 @@ class Style:
return self._link
@property
def transaprent_background(self) -> bool:
def transparent_background(self) -> bool:
"""Check if the style specified a transparent background."""
return self.bgcolor is None or self.bgcolor.is_default

View File

@ -353,7 +353,7 @@ class Syntax(JupyterMixin):
base_style = self._get_base_style()
justify: JustifyMethod = (
"default" if base_style.transaprent_background else "left"
"default" if base_style.transparent_background else "left"
)
text = Text(
@ -401,7 +401,7 @@ class Syntax(JupyterMixin):
def _get_number_styles(self, console: Console) -> Tuple[Style, Style, Style]:
"""Get background, number, and highlight styles for line numbers."""
background_style = self._get_base_style()
if background_style.transaprent_background:
if background_style.transparent_background:
return Style.null(), Style(dim=True), Style.null()
if console.color_system in ("256", "truecolor"):
number_style = Style.chain(
@ -428,7 +428,7 @@ class Syntax(JupyterMixin):
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:
transparent_background = self._get_base_style().transaprent_background
transparent_background = self._get_base_style().transparent_background
code_width = (
(options.max_width - self._numbers_column_width - 1)
if self.code_width is None

View File

@ -9,8 +9,6 @@ from typing import Callable, Dict, List, Optional, Type
from pygments.lexers import guess_lexer_for_filename
from pygments.token import (
Comment,
Generic,
Keyword,
Name,
Number,
@ -212,7 +210,7 @@ class Traceback:
traceback: Optional[TracebackType],
show_locals: bool = False,
) -> Trace:
"""Extrace traceback information.
"""Extract traceback information.
Args:
exc_type (Type[BaseException]): Exception type.
@ -342,7 +340,7 @@ class Traceback:
if syntax_error.filename != "<stdin>":
text = Text.assemble(
(f" {syntax_error.filename}", "pygments.string"),
(":", "pgments.text"),
(":", "pygments.text"),
(str(syntax_error.lineno), "pygments.number"),
style="pygments.text",
)

View File

@ -1,8 +1,34 @@
"""Tests for the higlighter classes."""
import pytest
from rich.highlighter import NullHighlighter
from rich.highlighter import NullHighlighter, ReprHighlighter
from rich.text import Span, Text
def test_wrong_type():
highlighter = NullHighlighter()
with pytest.raises(TypeError):
highlighter([])
@pytest.mark.parametrize(
"style_name, test_str",
[
("repr.eui48", "01-23-45-67-89-AB"), # 6x2 hyphen
("repr.eui64", "01-23-45-FF-FE-67-89-AB"), # 8x2 hyphen
("repr.eui48", "01:23:45:67:89:AB"), # 6x2 colon
("repr.eui64", "01:23:45:FF:FE:67:89:AB"), # 8x2 colon
("repr.eui48", "0123.4567.89AB"), # 3x4 dot
("repr.eui64", "0123.45FF.FE67.89AB"), # 4x4 dot
("repr.eui48", "ed-ed-ed-ed-ed-ed"), # lowercase
("repr.eui48", "ED-ED-ED-ED-ED-ED"), # uppercase
("repr.eui48", "Ed-Ed-Ed-Ed-Ed-Ed"), # mixed case
("repr.eui48", "0-00-1-01-2-02"), # dropped zero
],
)
def test_highlight_regex(style_name: str, test_str: str):
"""Tests for the regular expressions used in ReprHighlighter."""
text = Text(test_str)
highlighter = ReprHighlighter()
highlighter.highlight(text)
assert text._spans[-1] == Span(0, len(test_str), style_name)