Skip to content

Commit be834c9

Browse files
Accept callables for scroll_offset, min_brightness and max_brightness.
1 parent 21a18f3 commit be834c9

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

prompt_toolkit/layout/menus.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import math
22
from itertools import zip_longest
3-
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Tuple, TypeVar, cast
3+
from typing import (
4+
TYPE_CHECKING,
5+
Callable,
6+
Dict,
7+
Iterable,
8+
List,
9+
Optional,
10+
Tuple,
11+
TypeVar,
12+
Union,
13+
cast,
14+
)
415

516
from prompt_toolkit.application.current import get_app
617
from prompt_toolkit.buffer import CompletionState
@@ -261,7 +272,7 @@ class CompletionsMenu(ConditionalContainer):
261272
def __init__(
262273
self,
263274
max_height: Optional[int] = None,
264-
scroll_offset: int = 0,
275+
scroll_offset: Union[int, Callable[[], int]] = 0,
265276
extra_filter: FilterOrBool = True,
266277
display_arrows: FilterOrBool = False,
267278
z_index: int = 10 ** 8,

prompt_toolkit/styles/style_transformation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from prompt_toolkit.cache import memoized
1717
from prompt_toolkit.filters import FilterOrBool, to_filter
18-
from prompt_toolkit.utils import to_float, to_str
18+
from prompt_toolkit.utils import AnyFloat, to_float, to_str
1919

2020
from .base import ANSI_COLOR_NAMES, Attrs
2121
from .style import parse_color
@@ -153,7 +153,7 @@ class AdjustBrightnessStyleTransformation(StyleTransformation):
153153
"""
154154

155155
def __init__(
156-
self, min_brightness: float = 0.0, max_brightness: float = 1.0
156+
self, min_brightness: AnyFloat = 0.0, max_brightness: AnyFloat = 1.0
157157
) -> None:
158158

159159
self.min_brightness = min_brightness

prompt_toolkit/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"take_using_weights",
2929
"to_str",
3030
"to_int",
31+
"AnyFloat",
3132
"to_float",
3233
]
3334

@@ -284,7 +285,10 @@ def to_int(value: Union[Callable[[], int], int]) -> int:
284285
return int(value)
285286

286287

287-
def to_float(value: Union[Callable[[], float], float]) -> float:
288+
AnyFloat = Union[Callable[[], float], float]
289+
290+
291+
def to_float(value: AnyFloat) -> float:
288292
" Turn callable or float into float. "
289293
if callable(value):
290294
return to_float(value())

0 commit comments

Comments
 (0)