Skip to content

Commit 14d949a

Browse files
committed
Upgrade rich to 13.7.0
1 parent 7881c53 commit 14d949a

33 files changed

+373
-311
lines changed

news/rich.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade rich to 13.7.0

src/pip/_vendor/rich/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ def iter_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
207207

208208

209209
if __name__ == "__main__": # pragma: no cover
210-
211210
console = Console(
212211
file=io.StringIO(),
213212
force_terminal=True,

src/pip/_vendor/rich/_export_format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CONSOLE_HTML_FORMAT = """\
22
<!DOCTYPE html>
3+
<html>
34
<head>
45
<meta charset="UTF-8">
56
<style>
@@ -10,9 +11,8 @@
1011
}}
1112
</style>
1213
</head>
13-
<html>
1414
<body>
15-
<pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><code>{code}</code></pre>
15+
<pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><code style="font-family:inherit">{code}</code></pre>
1616
</body>
1717
</html>
1818
"""

src/pip/_vendor/rich/_ratio.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ def ratio_distribute(
151151

152152
@dataclass
153153
class E:
154-
155154
size: Optional[int] = None
156155
ratio: int = 1
157156
minimum_size: int = 1

src/pip/_vendor/rich/_windows.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class WindowsConsoleFeatures:
3030
)
3131

3232
except (AttributeError, ImportError, ValueError):
33-
3433
# Fallback if we can't load the Windows DLL
3534
def get_windows_console_features() -> WindowsConsoleFeatures:
3635
features = WindowsConsoleFeatures()

src/pip/_vendor/rich/_wrap.py

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
from __future__ import annotations
2+
13
import re
2-
from typing import Iterable, List, Tuple
4+
from typing import Iterable
35

46
from ._loop import loop_last
57
from .cells import cell_len, chop_cells
68

79
re_word = re.compile(r"\s*\S+\s*")
810

911

10-
def words(text: str) -> Iterable[Tuple[int, int, str]]:
12+
def words(text: str) -> Iterable[tuple[int, int, str]]:
13+
"""Yields each word from the text as a tuple
14+
containing (start_index, end_index, word). A "word" in this context may
15+
include the actual word and any whitespace to the right.
16+
"""
1117
position = 0
1218
word_match = re_word.match(text, position)
1319
while word_match is not None:
@@ -17,40 +23,71 @@ def words(text: str) -> Iterable[Tuple[int, int, str]]:
1723
word_match = re_word.match(text, end)
1824

1925

20-
def divide_line(text: str, width: int, fold: bool = True) -> List[int]:
21-
divides: List[int] = []
22-
append = divides.append
23-
line_position = 0
26+
def divide_line(text: str, width: int, fold: bool = True) -> list[int]:
27+
"""Given a string of text, and a width (measured in cells), return a list
28+
of cell offsets which the string should be split at in order for it to fit
29+
within the given width.
30+
31+
Args:
32+
text: The text to examine.
33+
width: The available cell width.
34+
fold: If True, words longer than `width` will be folded onto a new line.
35+
36+
Returns:
37+
A list of indices to break the line at.
38+
"""
39+
break_positions: list[int] = [] # offsets to insert the breaks at
40+
append = break_positions.append
41+
cell_offset = 0
2442
_cell_len = cell_len
43+
2544
for start, _end, word in words(text):
2645
word_length = _cell_len(word.rstrip())
27-
if line_position + word_length > width:
46+
remaining_space = width - cell_offset
47+
word_fits_remaining_space = remaining_space >= word_length
48+
49+
if word_fits_remaining_space:
50+
# Simplest case - the word fits within the remaining width for this line.
51+
cell_offset += _cell_len(word)
52+
else:
53+
# Not enough space remaining for this word on the current line.
2854
if word_length > width:
55+
# The word doesn't fit on any line, so we can't simply
56+
# place it on the next line...
2957
if fold:
30-
chopped_words = chop_cells(word, max_size=width, position=0)
31-
for last, line in loop_last(chopped_words):
58+
# Fold the word across multiple lines.
59+
folded_word = chop_cells(word, width=width)
60+
for last, line in loop_last(folded_word):
3261
if start:
3362
append(start)
34-
3563
if last:
36-
line_position = _cell_len(line)
64+
cell_offset = _cell_len(line)
3765
else:
3866
start += len(line)
3967
else:
68+
# Folding isn't allowed, so crop the word.
4069
if start:
4170
append(start)
42-
line_position = _cell_len(word)
43-
elif line_position and start:
71+
cell_offset = _cell_len(word)
72+
elif cell_offset and start:
73+
# The word doesn't fit within the remaining space on the current
74+
# line, but it *can* fit on to the next (empty) line.
4475
append(start)
45-
line_position = _cell_len(word)
46-
else:
47-
line_position += _cell_len(word)
48-
return divides
76+
cell_offset = _cell_len(word)
77+
78+
return break_positions
4979

5080

5181
if __name__ == "__main__": # pragma: no cover
5282
from .console import Console
5383

5484
console = Console(width=10)
5585
console.print("12345 abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ 12345")
56-
print(chop_cells("abcdefghijklmnopqrstuvwxyz", 10, position=2))
86+
print(chop_cells("abcdefghijklmnopqrstuvwxyz", 10))
87+
88+
console = Console(width=20)
89+
console.rule()
90+
console.print("TextualはPythonの高速アプリケーション開発フレームワークです")
91+
92+
console.rule()
93+
console.print("アプリケーションは1670万色を使用でき")

src/pip/_vendor/rich/align.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Align(JupyterMixin):
2727
renderable (RenderableType): A console renderable.
2828
align (AlignMethod): One of "left", "center", or "right""
2929
style (StyleType, optional): An optional style to apply to the background.
30-
vertical (Optional[VerticalAlginMethod], optional): Optional vertical align, one of "top", "middle", or "bottom". Defaults to None.
30+
vertical (Optional[VerticalAlignMethod], optional): Optional vertical align, one of "top", "middle", or "bottom". Defaults to None.
3131
pad (bool, optional): Pad the right with spaces. Defaults to True.
3232
width (int, optional): Restrict contents to given width, or None to use default width. Defaults to None.
3333
height (int, optional): Set height of align renderable, or None to fit to contents. Defaults to None.

src/pip/_vendor/rich/bar.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def __repr__(self) -> str:
4848
def __rich_console__(
4949
self, console: Console, options: ConsoleOptions
5050
) -> RenderResult:
51-
5251
width = min(
5352
self.width if self.width is not None else options.max_width,
5453
options.max_width,

0 commit comments

Comments
 (0)