Skip to content

Commit b7ce2dc

Browse files
committed
Added reset method
1 parent 83c38eb commit b7ce2dc

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Added
11+
12+
- Added Style.reset
813

914
## [13.3.2] - 2023-02-04
1015

rich/style.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,38 @@ def copy(self) -> "Style":
645645
style._meta = self._meta
646646
return style
647647

648+
@lru_cache(maxsize=128)
649+
def reset(self, link: bool = True, meta: bool = True) -> "Style":
650+
"""Get a copy of this style with optionally link and meta reset to default.
651+
652+
Args:
653+
link (bool, optional): Reset links. Defaults to True.
654+
meta (bool, optional): Reset meta. Defaults to True.
655+
656+
Returns:
657+
Style: New style object.
658+
"""
659+
if self._null:
660+
return NULL_STYLE
661+
style: Style = self.__new__(Style)
662+
style._ansi = self._ansi
663+
style._style_definition = self._style_definition
664+
style._color = self._color
665+
style._bgcolor = self._bgcolor
666+
style._attributes = self._attributes
667+
style._set_attributes = self._set_attributes
668+
if link:
669+
style._link = None
670+
style._link_id = ""
671+
else:
672+
style._link = self._link
673+
style._link_id = f"{randint(0, 999999)}" if self._link else ""
674+
style._hash = self._hash
675+
style._null = False
676+
677+
style._meta = None if meta else self._meta
678+
return style
679+
648680
def update_link(self, link: Optional[str] = None) -> "Style":
649681
"""Get a copy with a different value for link.
650682

rich/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ def fit(self, width: int) -> Lines:
12001200
width (int): Maximum characters in a line.
12011201
12021202
Returns:
1203-
Lines: List of lines.
1203+
Lines: Lines container.
12041204
"""
12051205
lines: Lines = Lines()
12061206
append = lines.append

0 commit comments

Comments
 (0)