mirror of https://github.com/Textualize/rich.git
optimized options
This commit is contained in:
parent
64755d41fa
commit
545f9b260a
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [9.12.2] - 2021-02-27
|
||||
|
||||
### Added
|
||||
|
||||
- Added ConsoleOptions.copy
|
||||
|
||||
### Changed
|
||||
|
||||
- Optimized ConsoleOptions.update
|
||||
|
||||
## [9.12.1] - 2021-02-27
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
name = "rich"
|
||||
homepage = "https://github.com/willmcgugan/rich"
|
||||
documentation = "https://rich.readthedocs.io/en/latest/"
|
||||
version = "9.12.1"
|
||||
version = "9.12.2"
|
||||
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
|
||||
authors = ["Will McGugan <willmcgugan@gmail.com>"]
|
||||
license = "MIT"
|
||||
|
|
|
@ -133,6 +133,16 @@ class ConsoleOptions:
|
|||
"""Check if renderables should use ascii only."""
|
||||
return not self.encoding.startswith("utf")
|
||||
|
||||
def copy(self) -> "ConsoleOptions":
|
||||
"""Return a copy of the options.
|
||||
|
||||
Returns:
|
||||
ConsoleOptions: a copy of self.
|
||||
"""
|
||||
options = ConsoleOptions.__new__(ConsoleOptions)
|
||||
options.__dict__ = self.__dict__.copy()
|
||||
return options
|
||||
|
||||
def update(
|
||||
self,
|
||||
width: Union[int, NoChange] = NO_CHANGE,
|
||||
|
@ -145,7 +155,7 @@ class ConsoleOptions:
|
|||
height: Union[Optional[int], NoChange] = NO_CHANGE,
|
||||
) -> "ConsoleOptions":
|
||||
"""Update values, return a copy."""
|
||||
options = replace(self)
|
||||
options = self.copy()
|
||||
if not isinstance(width, NoChange):
|
||||
options.min_width = options.max_width = max(0, width)
|
||||
if not isinstance(min_width, NoChange):
|
||||
|
@ -173,8 +183,8 @@ class ConsoleOptions:
|
|||
Returns:
|
||||
~ConsoleOptions: New console options instance
|
||||
"""
|
||||
width = max(0, width)
|
||||
options = replace(self, min_width=width, max_width=width)
|
||||
options = self.copy()
|
||||
options.min_width = options.max_width = max(0, width)
|
||||
return options
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue