Skip to main content

A custom tags widget to be used in textual applications

Project description

Ruff PyPI-Server Pyversions License: MIT Downloads Coverage Status

textual-tags

demo_image

This library provides a custom tags widget called Tags, which can be easily added into your existing textual application.

Requires a Nerdfont to render the round corners of the Tag labels.

Features

  • Can be initiated with a predefined set/list of tags, similar entries will be ignored
  • Consists of a TagInput, with autocompletion powered by textual-autocomplete for existing tags and displayed tags wrapped in a flexbox-like container
  • Two different ways to display the tags (with x at the end or without)
  • Option to also add new not predefined tags, which are then also available for autocompletion
  • vim-like completion control

Installation

textual-tags is hosted on PyPi and can be installed with:

pip install textual-tags

or add it to your project using uv with:

uv add textual-tags

Demo App

You can run the demo app after installation with textual-tags or using uv with:

uvx textual-tags

Usage

Here is an exampke usage of the Tags-widget in a textual App. You can also check the demo app here.

from textual.app import App

from textual_tags import Tags

PRE_DEFINED_TAGS = [
    "uv",
    "Terminal",
    "tcss",
    "Textual",
    "Tags",
    "Widget",
    "Python",
    "TUI",
    "Highlander"
]

class TagsApp(App):
    DEFAULT_CSS = """
    Tags {
        width:50;
    }
    """
    def compose(self):
        yield Tags(
            # list/set of tags to start with
            tag_values=PRE_DEFINED_TAGS,
            # Show Tag-Labels as `TAG x` instead of ' TAG '
            show_x=False,
            # All tags are selected on startup
            start_with_tags_selected=True,
            # Allow to enter custom new tags and dont hide TagInput if all tags are selected
            # Also allows delete/edit of last tag when pressing `backspace` on empty input
            allow_new_tags=False,
        )

def main():
    app = TagsApp()
    app.run()

if __name__ == '__main__':
    main()

Messages

Tags sends two messages:

  • Tag.Removed, send when a tag is removed in any way
  • Tag.Focused, send when a tag is focused
  • Tag.Hovered, send when a tag is hovered
  • Tag.Selected, send when a tag is selected
  • TagAutoComplete.Applied, send when a completion option is applied

Issues/Feedback

Feel free to reach out and share your feedback, or open an Issue, if something doesnt work as expected. Also check the Changelog for new updates.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textual_tags-0.3.1.tar.gz (103.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textual_tags-0.3.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file textual_tags-0.3.1.tar.gz.

File metadata

  • Download URL: textual_tags-0.3.1.tar.gz
  • Upload date:
  • Size: 103.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for textual_tags-0.3.1.tar.gz
Algorithm Hash digest
SHA256 68757f8f47cb75b6612016f04a6e1640e0200b84955be63ccf2800da380df815
MD5 6cbfb2796ebb3b8b9a03264043ecd15f
BLAKE2b-256 6d581809bfcd66eecf7f056d11670cc3644dbdf2fb699869552516c1400c301b

See more details on using hashes here.

File details

Details for the file textual_tags-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for textual_tags-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b287e722dd93668d15046f7c63af3a5d79c7c0e48b3d0e3ab732234440f98dbb
MD5 3d59569e67fcc0847758c7a61d6e6ff6
BLAKE2b-256 57493d9e59a65ae2be157d151453272348e2e2757b3b6c18316500cc589b0112

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page