Skip to content

Commit

Permalink
optimized options
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Feb 27, 2021
1 parent 64755d4 commit 545f9b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 13 additions & 3 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ def ascii_only(self) -> bool:
"""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,
Expand All @@ -145,7 +155,7 @@ def update(
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):
Expand Down Expand Up @@ -173,8 +183,8 @@ def update_width(self, width: int) -> "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


Expand Down

0 comments on commit 545f9b2

Please sign in to comment.