Metadata-Version: 2.4
Name: textual-searchable-selectionlist
Version: 0.0.6
Summary: Add search to Textual SelectionList.
Author: Joao Coelho
Description-Content-Type: text/markdown
Classifier: License :: OSI Approved :: MIT License
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Development Status :: 5 - Production/Stable
License-File: LICENSE.txt
Requires-Dist: textual
Project-URL: Home, https://github.com/joaonc/textual-searchable-selectionlist

# Searchable SelectionList
[![image](https://img.shields.io/pypi/v/textual-searchable-selectionlist.svg)](https://pypi.python.org/pypi/textual-searchable-selectionlist)
[![Project License - MIT](https://img.shields.io/pypi/l/textual-searchable-selectionlist.svg)](./LICENSE.txt)

Add search to Textual's [SelectionList](https://textual.textualize.io/widgets/selection_list/).

* Selectable items can be filtered by substring.
* Select one or multiple items.
* Search is case-insensitive.
* Title and description can be customized.

## Installation
```bash
pip install textual-searchable-selectionlist
```

## Usage
```python
from textual_searchable_selectionlist.options import SelectionStrategy
from textual_searchable_selectionlist.select import select, select_enum

selected = select(
    ['John', 'Jane', 'James'],
    selection_strategy=SelectionStrategy.MULTIPLE,
    search_title='Select people',
)

# Enums
# class Color(Enum):
#     RED = 'red'
#     GREEN = 'green'
#
# selected_colors = select_enum(Color, selection_strategy=SelectionStrategy.ONE)
```

## Events and callbacks
Use `selected_callback` when embedding the widget, or listen for the
`SearchableListWidget.Selected` message in your app.

```python
from textual.app import App, ComposeResult
from textual_searchable_selectionlist.options import SelectionStrategy
from textual_searchable_selectionlist.searchable_list_widget import SearchableListWidget


class MyApp(App):
    def compose(self) -> ComposeResult:
        yield SearchableListWidget(
            "Alpha",
            "Beta",
            "Gamma",
            selection_strategy=SelectionStrategy.ONE,
            selected_callback=self._on_selected_callback,
        )

    def _on_selected_callback(self, selected: list[str]):
        self.log(f"Callback selected: {selected}")

    def on_searchable_list_widget_selected(
        self, event: SearchableListWidget.Selected
    ):
        self.log(f"Event selected: {event.selected}")
```

## Testing
There are currently no automated tests. Manual testing can be done by running:
```bash
python tests/manual/searchable_selection_list_select.py
```

