Skip to content

Commit

Permalink
Sync with prompt_toolkit pull request #1838
Browse files Browse the repository at this point in the history
We sent vertmenu* to prompt_toolkit.
  • Loading branch information
lpenz committed Dec 31, 2023
1 parent 92af83b commit 8b15609
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/ptvertmenu/vertmenu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Vertical menu widget for prompt-toolkit"""

from typing import Callable, Iterable, Optional
from typing import Callable, Iterable, Optional, Tuple

from prompt_toolkit.application import get_app
from prompt_toolkit.key_binding import KeyBindings
Expand Down Expand Up @@ -102,7 +102,7 @@ def preferred_width(self) -> int:
return width

@property
def items(self) -> tuple[Item, ...]:
def items(self) -> Tuple[Item, ...]:
return self.control.items

@items.setter
Expand Down
7 changes: 4 additions & 3 deletions src/ptvertmenu/vertmenuuicontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Iterator,
NewType,
Optional,
Tuple,
cast,
)

Expand All @@ -28,7 +29,7 @@
if TYPE_CHECKING:
from prompt_toolkit.key_binding.key_bindings import NotImplementedOrNone

Item = tuple[AnyFormattedText, Any]
Item = Tuple[AnyFormattedText, Any]
Index = NewType("Index", int)


Expand Down Expand Up @@ -63,7 +64,7 @@ def handle_selected(self) -> None:
if self.selected_handler is not None:
self.selected_handler(self.selected_item, self.selected)

def _items_enumerate(self) -> Iterator[tuple[Index, Item]]:
def _items_enumerate(self) -> Iterator[Tuple[Index, Item]]:
for index, item in enumerate(self._items):
yield Index(index), item

Expand All @@ -82,7 +83,7 @@ def _gen_lineno_mappings(self) -> None:
self._width = max(self._width, len(line))

@property
def items(self) -> tuple[Item, ...]:
def items(self) -> Tuple[Item, ...]:
return self._items

@items.setter
Expand Down
14 changes: 7 additions & 7 deletions tests/test_ptvertmenuuicontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_items(self) -> None:
self.control.items = tuple([self.items[0]] + self.items[2:])
self.assertEqual(self.control.selected, 0)
self.assertEqual(self.control.selected_item, ("breakfast", "breakfast"))
self.control.items = tuple()
self.control.items = ()
self.assertEqual(self.control.selected, None)
self.assertEqual(self.control.selected_item, None)
self.control.items = tuple(self.items)
Expand All @@ -111,13 +111,13 @@ def test_items(self) -> None:
self.assertEqual(self.control.selected_item, ("breakfast", "breakfast"))

def test_items_width_update(self) -> None:
bigitem = ", ".join((str(i) for i in range(50)))
self.control.items = tuple([(bigitem, bigitem)])
bigitem = ", ".join(str(i) for i in range(50))
self.control.items = ((bigitem, bigitem),)
width = self.control.preferred_width(999)
self.assertEqual(width, len(bigitem))
# Check if using a smaller bigitem updates the width
bigitem = ", ".join((str(i) for i in range(30)))
self.control.items = tuple([(bigitem, bigitem)])
bigitem = ", ".join(str(i) for i in range(30))
self.control.items = ((bigitem, bigitem),)
width = self.control.preferred_width(999)
self.assertEqual(width, len(bigitem))

Expand All @@ -137,7 +137,7 @@ def test_mouse(self) -> None:

class TestVertMenuUIControlEmpty(unittest.TestCase):
def setUp(self) -> None:
self.items: tuple[Item, ...] = tuple()
self.items: tuple[Item, ...] = ()
self.control = VertMenuUIControl(self.items)

def test_methods(self) -> None:
Expand Down Expand Up @@ -174,7 +174,7 @@ def setUp(self) -> None:
self.control = VertMenuUIControl(self.items)

def label(self, item: int) -> str:
return "\n".join((f"item {item} line {lineno}" for lineno in range(self.LINES)))
return "\n".join(f"item {item} line {lineno}" for lineno in range(self.LINES))

def test_down_up(self) -> None:
assert self.control.selected is not None
Expand Down

0 comments on commit 8b15609

Please sign in to comment.