From b33a7c94a3000197ff91956aef1be09b054a9cf0 Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 9 Jun 2026 22:48:47 +0900 Subject: [PATCH] Make pick module callable with cadule --- README.md | 3 ++- pyproject.toml | 1 + setup.cfg | 3 +++ src/pick/__init__.py | 32 ++++++++++++++++++++++++++++++++ uv.lock | 11 +++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e6c9fd..442c4fc 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ Then pass `backend="blessed"` to `pick(...)`. **pick** comes with a simple api: - >>> from pick import pick + >>> import pick + >>> # You can also use `from pick import pick` if you do not want to use cadule's magic: https://github.com/aisk/cadule >>> title = 'Please choose your favorite programming language: ' >>> options = ['Java', 'JavaScript', 'Python', 'PHP', 'C++', 'Erlang', 'Haskell'] diff --git a/pyproject.toml b/pyproject.toml index e30194c..395f61a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ keywords = ["terminal", "gui"] requires-python = ">=3.8" dependencies = [ + "cadule>=0.0.1,<1.0.0", "windows-curses>=2.2.0; platform_system=='Windows'", ] diff --git a/setup.cfg b/setup.cfg index 0158047..c33572f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,3 +6,6 @@ warn_unused_ignores = True [mypy-blessed] ignore_missing_imports = True + +[mypy-cadule] +ignore_missing_imports = True diff --git a/src/pick/__init__.py b/src/pick/__init__.py index 3ca398a..d9535a8 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -4,6 +4,8 @@ from dataclasses import dataclass, field from typing import Any, Container, Generic, Iterable, List, Optional, Sequence, Tuple, TypeVar, Union +import cadule + from .backend import Backend from .blessed_backend import BlessedBackend from .curses_backend import CursesBackend @@ -16,6 +18,7 @@ "Backend", "CursesBackend", "BlessedBackend", + "__call__", "SYMBOL_CIRCLE_FILLED", "SYMBOL_CIRCLE_EMPTY", ] @@ -302,3 +305,32 @@ def pick( backend, ) return picker.start() + + +@cadule +def __call__( + options: Sequence[OPTION_T], + title: Optional[str] = None, + indicator: str = "*", + default_index: int = 0, + multiselect: bool = False, + min_selection_count: int = 0, + screen: Optional[curses.window] = None, + position: Position = Position(0, 0), + clear_screen: bool = True, + quit_keys: Optional[Union[Container[int], Iterable[int]]] = None, + backend: Union[str, Backend] = "curses", +): + return pick( + options, + title, + indicator, + default_index, + multiselect, + min_selection_count, + screen, + position, + clear_screen, + quit_keys, + backend, + ) diff --git a/uv.lock b/uv.lock index fb1c828..b84cadd 100644 --- a/uv.lock +++ b/uv.lock @@ -30,6 +30,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d2/46/c41f906f2488e14ab65ac77101f9511779fb28c653484bd79ac13f2f21ee/blessed-1.42.0-py3-none-any.whl", hash = "sha256:f96c4a6dc664b48e0b832fa732acc16df67abd30f0ec35babf99025982f21852", size = 129863, upload-time = "2026-05-20T16:03:15.622Z" }, ] +[[package]] +name = "cadule" +version = "0.0.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/42/b1/d09010dcce164eeda7ceec92d3cca739ee30c0b1d6203b9589819b57a8c5/cadule-0.0.1.tar.gz", hash = "sha256:95aa7c467c67c19c392d091f0567a5a2d883cf35b69c64abfb668f4f77867b5e", size = 2745, upload-time = "2025-12-08T14:07:32.666Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1e/3d/e219e5fa6792de1aaf3826398014365ea880a4e17c0bfbb797e4d2ea24ab/cadule-0.0.1-py3-none-any.whl", hash = "sha256:265ff4b32db09adced2b0111fd6e283a14f24340e0a9235c74c4b3f944f33916", size = 2983, upload-time = "2025-12-08T14:07:31.267Z" }, +] + [[package]] name = "cfgv" version = "3.4.0" @@ -447,6 +456,7 @@ name = "pick" version = "2.6.0" source = { editable = "." } dependencies = [ + { name = "cadule" }, { name = "windows-curses", marker = "sys_platform == 'win32'" }, ] @@ -470,6 +480,7 @@ dev = [ [package.metadata] requires-dist = [ { name = "blessed", marker = "extra == 'blessed'", specifier = ">=1.17.0" }, + { name = "cadule", specifier = ">=0.0.1,<1.0.0" }, { name = "windows-curses", marker = "sys_platform == 'win32'", specifier = ">=2.2.0" }, ] provides-extras = ["blessed"]