textual-inputs


Nametextual-inputs JSON
Version 0.2.6 PyPI version JSON
download
home_page
Summarytextual-inputs is a collection of input widgets for the Textual TUI framework
upload_time2022-06-12 01:07:51
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT
keywords tui terminal widget
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Textual Inputs 🔡

[![Python Versions](https://shields.io/pypi/pyversions/textual-inputs)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

Textual Inputs is a collection of input widgets for the [Textual](https://github.com/willmcgugan/textual) TUI framework.

> ⚠️ This library is experimental and its interfaces will change. While
> Textual Inputs is pre-alpha please pin your projects to the minor release
> number to avoid breaking changes. For example: textual-inputs=0.2.\*

## News

### v0.2.6

- Support for text overflow in TextInput
- Patch for crash when IntegerInput is empty and backspace is pressed.

## Quick Start

Installation

```bash
python -m pip install textual-inputs~=0.2.6
```

To use Textual Inputs

```python
from textual_inputs import TextInput, IntegerInput
```

Checkout the [examples](https://github.com/sirfuzzalot/textual-inputs/tree/main/examples) for reference.

```bash
git clone https://github.com/sirfuzzalot/textual-inputs.git
cd textual-inputs
python3 -m venv venv
source venv/bin/activate
python -m pip install -e .
python examples/simple_form.py
```

## Widgets

### TextInput 🔡

- value - string
- one line of text with overflow support
- placeholder and title support
- password mode to hide input
- syntax mode to highlight code
- support for Unicode characters
- controls: arrow right/left, home, end, delete, backspace/ctrl+h, escape
- emits - InputOnChange, InputOnFocus messages

### IntegerInput 🔢

- value - integer or None
- placeholder and title support
- type a number or arrow up/down to increment/decrement the integer.
- controls: arrow right/left, home, end, delete, backspace/ctrl+h, escape
- emits - InputOnChange, InputOnFocus messages

## Features

### One-Line Syntax Highlighting

Textual Inputs takes advantage of `rich`'s built-in Syntax feature. To
add highlighting to your input text set the `syntax` argument to a language
supported by `pygments`. Currently this is set to the default theme.

**⚠️ THIS FEATURE IS LIMITED TO ONE LINE OF TEXT**

```python
TextInput(
    name="code",
    placeholder="enter some python code...",
    title="Code",
    syntax="python",
)
```

### Event Handlers

Textual Inputs helps make the event handler process easier by providing
the following convenient properties for inputs.

- on_change_handler_name
- on_focus_handler_name

```python
email = TextInput(name="email", title="Email")
email.on_change_handler_name = "handle_email_on_change"
email.on_focus_handler_name = "handle_email_on_focus"
```

Under the hood setting this attribute this will generate a `Message` class
with the appropriate name for Textual to send it to the handler name provided.
You'll then want add the handler to the input's parent or the App instance.
If you opt not to customize these handlers, their values will be the
default `handle_input_on_change` and `handle_input_on_focus`. See
`examples/simple_form.py` for a working example.

## API Reference

Textual Inputs has two widgets, here are their attributes.

```python
class TextInput(Widget):
    """
    A simple text input widget.

    Args:
        name (Optional[str]): The unique name of the widget. If None, the
            widget will be automatically named.
        value (str, optional): Defaults to "". The starting text value.
        placeholder (str, optional): Defaults to "". Text that appears
            in the widget when value is "" and the widget is not focused.
        title (str, optional): Defaults to "". A title on the top left
            of the widget's border.
        password (bool, optional): Defaults to False. Hides the text
            input, replacing it with bullets.
        syntax (Optional[str]): the name of the language for syntax highlighting.

    Attributes:
        value (str): the value of the text field
        placeholder (str): The placeholder message.
        title (str): The displayed title of the widget.
        has_password (bool): True if the text field masks the input.
        syntax (Optional[str]): the name of the language for syntax highlighting.
        has_focus (bool): True if the widget is focused.
        cursor (Tuple[str, Style]): The character used for the cursor
            and a rich Style object defining its appearance.
        on_change_handler_name (str): name of handler function to be
            called when an on change event occurs. Defaults to
            handle_input_on_change.
        on_focus_handler_name (name): name of handler function to be
            called when an on focus event occurs. Defaults to
            handle_input_on_focus.

    Events:
        InputOnChange: Emitted when the contents of the input changes.
        InputOnFocus: Emitted when the widget becomes focused.

    Examples:

    .. code-block:: python

        from textual_inputs import TextInput

        email_input = TextInput(
            name="email",
            placeholder="enter your email address...",
            title="Email",
        )

    """
```

```python
class IntegerInput(Widget):
    """
    A simple integer input widget.

    Args:
        name (Optional[str]): The unique name of the widget. If None, the
            widget will be automatically named.
        value (Optional[int]): The starting integer value.
        placeholder (Union[str, int, optional): Defaults to "". Text that
            appears in the widget when value is "" and the widget is not focused.
        title (str, optional): Defaults to "". A title on the top left
            of the widget's border.

    Attributes:
        value (Union[int, None]): the value of the input field
        placeholder (str): The placeholder message.
        title (str): The displayed title of the widget.
        has_focus (bool): True if the widget is focused.
        cursor (Tuple[str, Style]): The character used for the cursor
            and a rich Style object defining its appearance.
        on_change_handler_name (str): name of handler function to be
            called when an on change event occurs. Defaults to
            handle_input_on_change.
        on_focus_handler_name (name): name of handler function to be
            called when an on focus event occurs. Defaults to
            handle_input_on_focus.

    Events:
        InputOnChange: Emitted when the contents of the input changes.
        InputOnFocus: Emitted when the widget becomes focused.

    Examples:

    .. code-block:: python

        from textual_inputs import IntegerInput

        age_input = IntegerInput(
            name="age",
            placeholder="enter your age...",
            title="Age",
        )

    """
```

## Contributing

See the [Contributing Guide](https://github.com/sirfuzzalot/textual-inputs/blob/main/CONTRIBUTING.md).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "textual-inputs",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "tui,terminal,widget",
    "author": "",
    "author_email": "57846408+sirfuzzalot@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/6c/cc/3600389048dff976fc607272161aeee72d084b36730b7f72124902e44905/textual-inputs-0.2.6.tar.gz",
    "platform": null,
    "description": "# Textual Inputs \ud83d\udd21\n\n[![Python Versions](https://shields.io/pypi/pyversions/textual-inputs)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)\n\nTextual Inputs is a collection of input widgets for the [Textual](https://github.com/willmcgugan/textual) TUI framework.\n\n> \u26a0\ufe0f This library is experimental and its interfaces will change. While\n> Textual Inputs is pre-alpha please pin your projects to the minor release\n> number to avoid breaking changes. For example: textual-inputs=0.2.\\*\n\n## News\n\n### v0.2.6\n\n- Support for text overflow in TextInput\n- Patch for crash when IntegerInput is empty and backspace is pressed.\n\n## Quick Start\n\nInstallation\n\n```bash\npython -m pip install textual-inputs~=0.2.6\n```\n\nTo use Textual Inputs\n\n```python\nfrom textual_inputs import TextInput, IntegerInput\n```\n\nCheckout the [examples](https://github.com/sirfuzzalot/textual-inputs/tree/main/examples) for reference.\n\n```bash\ngit clone https://github.com/sirfuzzalot/textual-inputs.git\ncd textual-inputs\npython3 -m venv venv\nsource venv/bin/activate\npython -m pip install -e .\npython examples/simple_form.py\n```\n\n## Widgets\n\n### TextInput \ud83d\udd21\n\n- value - string\n- one line of text with overflow support\n- placeholder and title support\n- password mode to hide input\n- syntax mode to highlight code\n- support for Unicode characters\n- controls: arrow right/left, home, end, delete, backspace/ctrl+h, escape\n- emits - InputOnChange, InputOnFocus messages\n\n### IntegerInput \ud83d\udd22\n\n- value - integer or None\n- placeholder and title support\n- type a number or arrow up/down to increment/decrement the integer.\n- controls: arrow right/left, home, end, delete, backspace/ctrl+h, escape\n- emits - InputOnChange, InputOnFocus messages\n\n## Features\n\n### One-Line Syntax Highlighting\n\nTextual Inputs takes advantage of `rich`'s built-in Syntax feature. To\nadd highlighting to your input text set the `syntax` argument to a language\nsupported by `pygments`. Currently this is set to the default theme.\n\n**\u26a0\ufe0f THIS FEATURE IS LIMITED TO ONE LINE OF TEXT**\n\n```python\nTextInput(\n    name=\"code\",\n    placeholder=\"enter some python code...\",\n    title=\"Code\",\n    syntax=\"python\",\n)\n```\n\n### Event Handlers\n\nTextual Inputs helps make the event handler process easier by providing\nthe following convenient properties for inputs.\n\n- on_change_handler_name\n- on_focus_handler_name\n\n```python\nemail = TextInput(name=\"email\", title=\"Email\")\nemail.on_change_handler_name = \"handle_email_on_change\"\nemail.on_focus_handler_name = \"handle_email_on_focus\"\n```\n\nUnder the hood setting this attribute this will generate a `Message` class\nwith the appropriate name for Textual to send it to the handler name provided.\nYou'll then want add the handler to the input's parent or the App instance.\nIf you opt not to customize these handlers, their values will be the\ndefault `handle_input_on_change` and `handle_input_on_focus`. See\n`examples/simple_form.py` for a working example.\n\n## API Reference\n\nTextual Inputs has two widgets, here are their attributes.\n\n```python\nclass TextInput(Widget):\n    \"\"\"\n    A simple text input widget.\n\n    Args:\n        name (Optional[str]): The unique name of the widget. If None, the\n            widget will be automatically named.\n        value (str, optional): Defaults to \"\". The starting text value.\n        placeholder (str, optional): Defaults to \"\". Text that appears\n            in the widget when value is \"\" and the widget is not focused.\n        title (str, optional): Defaults to \"\". A title on the top left\n            of the widget's border.\n        password (bool, optional): Defaults to False. Hides the text\n            input, replacing it with bullets.\n        syntax (Optional[str]): the name of the language for syntax highlighting.\n\n    Attributes:\n        value (str): the value of the text field\n        placeholder (str): The placeholder message.\n        title (str): The displayed title of the widget.\n        has_password (bool): True if the text field masks the input.\n        syntax (Optional[str]): the name of the language for syntax highlighting.\n        has_focus (bool): True if the widget is focused.\n        cursor (Tuple[str, Style]): The character used for the cursor\n            and a rich Style object defining its appearance.\n        on_change_handler_name (str): name of handler function to be\n            called when an on change event occurs. Defaults to\n            handle_input_on_change.\n        on_focus_handler_name (name): name of handler function to be\n            called when an on focus event occurs. Defaults to\n            handle_input_on_focus.\n\n    Events:\n        InputOnChange: Emitted when the contents of the input changes.\n        InputOnFocus: Emitted when the widget becomes focused.\n\n    Examples:\n\n    .. code-block:: python\n\n        from textual_inputs import TextInput\n\n        email_input = TextInput(\n            name=\"email\",\n            placeholder=\"enter your email address...\",\n            title=\"Email\",\n        )\n\n    \"\"\"\n```\n\n```python\nclass IntegerInput(Widget):\n    \"\"\"\n    A simple integer input widget.\n\n    Args:\n        name (Optional[str]): The unique name of the widget. If None, the\n            widget will be automatically named.\n        value (Optional[int]): The starting integer value.\n        placeholder (Union[str, int, optional): Defaults to \"\". Text that\n            appears in the widget when value is \"\" and the widget is not focused.\n        title (str, optional): Defaults to \"\". A title on the top left\n            of the widget's border.\n\n    Attributes:\n        value (Union[int, None]): the value of the input field\n        placeholder (str): The placeholder message.\n        title (str): The displayed title of the widget.\n        has_focus (bool): True if the widget is focused.\n        cursor (Tuple[str, Style]): The character used for the cursor\n            and a rich Style object defining its appearance.\n        on_change_handler_name (str): name of handler function to be\n            called when an on change event occurs. Defaults to\n            handle_input_on_change.\n        on_focus_handler_name (name): name of handler function to be\n            called when an on focus event occurs. Defaults to\n            handle_input_on_focus.\n\n    Events:\n        InputOnChange: Emitted when the contents of the input changes.\n        InputOnFocus: Emitted when the widget becomes focused.\n\n    Examples:\n\n    .. code-block:: python\n\n        from textual_inputs import IntegerInput\n\n        age_input = IntegerInput(\n            name=\"age\",\n            placeholder=\"enter your age...\",\n            title=\"Age\",\n        )\n\n    \"\"\"\n```\n\n## Contributing\n\nSee the [Contributing Guide](https://github.com/sirfuzzalot/textual-inputs/blob/main/CONTRIBUTING.md).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "textual-inputs is a collection of input widgets for the Textual TUI framework",
    "version": "0.2.6",
    "project_urls": {
        "Documentation": "https://github.com/sirfuzzalot/textual-inputs",
        "Source": "https://github.com/sirfuzzalot/textual-inputs",
        "Tracker": "https://github.com/sirfuzzalot/textual-inputs/issues"
    },
    "split_keywords": [
        "tui",
        "terminal",
        "widget"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3fd3ed99c7d38b86877f75545114355aeb57259278423df6f967737937468e5f",
                "md5": "f9399e520e88725e12f1d049b997e9cc",
                "sha256": "5fe988772453f78c755112728e4357da6a97a0b8627202c889089fc5e576998b"
            },
            "downloads": -1,
            "filename": "textual_inputs-0.2.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f9399e520e88725e12f1d049b997e9cc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 11441,
            "upload_time": "2022-06-12T01:07:49",
            "upload_time_iso_8601": "2022-06-12T01:07:49.710597Z",
            "url": "https://files.pythonhosted.org/packages/3f/d3/ed99c7d38b86877f75545114355aeb57259278423df6f967737937468e5f/textual_inputs-0.2.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6ccc3600389048dff976fc607272161aeee72d084b36730b7f72124902e44905",
                "md5": "9c62977a6798bd6630b805870ae13498",
                "sha256": "bb571ee88d378a565190027c339770678f4cc57384b051fd6d594a0627a6c8fb"
            },
            "downloads": -1,
            "filename": "textual-inputs-0.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "9c62977a6798bd6630b805870ae13498",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 10754,
            "upload_time": "2022-06-12T01:07:51",
            "upload_time_iso_8601": "2022-06-12T01:07:51.263458Z",
            "url": "https://files.pythonhosted.org/packages/6c/cc/3600389048dff976fc607272161aeee72d084b36730b7f72124902e44905/textual-inputs-0.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-06-12 01:07:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sirfuzzalot",
    "github_project": "textual-inputs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "textual-inputs"
}
        
Elapsed time: 0.26106s