Skip to content

Commit

Permalink
allow integer values for multi
Browse files Browse the repository at this point in the history
  • Loading branch information
oerpli authored and Abraham Hinteregger committed Apr 12, 2020
1 parent 2d13fdf commit 724dd25
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
13 changes: 11 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ The following is the full list of parameters. Please pass them as
For both modes, the function returns ``None`` if nothing is matched or
a user cancelled.

``False`` by default.
It is also possible to provide an integer value ``>0`` instead of ``True``/``False``.
This limits the amount of possible selections. If an integer is provided,
the return value is a list if one or more elements were selected and ``None`` else.

``None`` by default.

Corresponds to ``-m``/``--multi`` option.

Expand Down Expand Up @@ -183,12 +187,17 @@ is 3.4.5.
.. _Semantic Versioning: http://semver.org/


Version 0.6.0.20.0
~~~~~~~~~~~~~~~~~~

To be released. Bundles ``fzf`` 0.20.0.

- Changed ``multi`` option to allow numeric values as well.
e.g. ``iterfzf(list, multi=15)`` allows the selection of at most 15 items.
[`#11`__ by Abraham Hinteregger]

__ https://github.com/dahlia/iterfzf/pull/11


Version 0.5.0.20.0
~~~~~~~~~~~~~~~~~~
Expand Down
12 changes: 9 additions & 3 deletions iterfzf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def iterfzf(
# Search mode:
extended=True, exact=False, case_sensitive=None,
# Interface:
multi=False, mouse=True, print_query=False,
multi=None, mouse=True, print_query=False,
# Layout:
prompt='> ',
preview=None,
Expand All @@ -43,8 +43,14 @@ def iterfzf(
cmd.append('+i' if case_sensitive else '-i')
if exact:
cmd.append('--exact')
if multi:
cmd.append('--multi')
if multi is not None:
if isinstance(multi, bool):
if multi:
cmd.append('--multi')
elif isinstance(multi, int) and multi > 0:
cmd.append('--multi=' + str(multi))
else:
raise ValueError('multi must be either bool or an int>0')
if not mouse:
cmd.append('--no-mouse')
if print_query:
Expand Down
4 changes: 2 additions & 2 deletions iterfzf/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import AnyStr, Iterable, Optional
from typing import AnyStr, Iterable, Optional, Union

BUNDLED_EXECUTABLE: Optional[str]

Expand All @@ -9,7 +9,7 @@ def iterfzf(
exact: bool = ...,
case_sensitive: Optional[bool] = ...,
# Interface:
multi: bool = ...,
multi: Optional[Union[bool,int]] = ...,
mouse: bool = ...,
print_query: bool = ...,
# Layout:
Expand Down

0 comments on commit 724dd25

Please sign in to comment.