Skip to content

Commit

Permalink
optimized measure
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jun 28, 2020
1 parent 5e8673d commit 0d64d38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Enabled supported box chars for legacy Windows, and introduce `safe_box` flag
- Disable hyperlinks on legacy Windows
- Constructors for Rule and Panel now have keyword only arguments (reason for major version bump)
- Table.add_colum added keyword only arguments

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion rich/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def __init__(
) -> None:
self.renderable = renderable
self.box = box
self.safe_box = safe_box
self.expand = expand
self.style = style
self.width = width
self.padding = padding
self.safe_box = safe_box

def __rich_console__(
self, console: Console, options: ConsoleOptions
Expand Down
17 changes: 8 additions & 9 deletions rich/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def __init__(
self.caption = caption
self.width = width
self.box = box
self.safe_box = safe_box
self._padding = Padding.unpack(padding)
self.pad_edge = pad_edge
self.expand = expand
Expand All @@ -164,7 +165,6 @@ def __init__(
self.border_style = border_style
self.title_style = title_style
self.caption_style = title_style
self.safe_box = safe_box
self._row_count = 0
self.row_styles = list(row_styles or [])

Expand Down Expand Up @@ -227,14 +227,12 @@ def __rich_measure__(self, console: "Console", max_width: int) -> Measurement:

extra_width = self._extra_width
_measure_column = self._measure_column
minimum_width = sum(
_measure_column(console, column, max_width).minimum
for column in self.columns
)
maximum_width = sum(
_measure_column(console, column, max_width).maximum
for column in self.columns
)

measurements = [
_measure_column(console, column, max_width) for column in self.columns
]
minimum_width = sum(measurement.minimum for measurement in measurements)
maximum_width = sum(measurement.maximum for measurement in measurements)
return Measurement(minimum_width + extra_width, maximum_width + extra_width)

@property
Expand All @@ -252,6 +250,7 @@ def add_column(
self,
header: "RenderableType" = "",
footer: "RenderableType" = "",
*,
header_style: StyleType = None,
footer_style: StyleType = None,
style: StyleType = None,
Expand Down

0 comments on commit 0d64d38

Please sign in to comment.