Skip to main content

Clack-style terminal UI primitives for prompt-first Python TUIs.

Project description

griphTUI

Minimal and ergonomic Clack-style terminal UI primitives for Python CLIs/TUIs.

PyPI - Version PyPI - Downloads

Install

uv add griphtui

The basics

GriphTUI is heavily inspired by Clack, and follows many of the same basic principles.

You'll probably want to begin with an intro:

import griphtui as gtui

gtui.intro("The grand survey")

...after which you can employ a range of primitives to prompt the user:

# section header
gtui.section("Let's talk about trains")

# text input
gtui.text("What's your favorite train?")

# select
gtui.select(
    "Can this train drift?",
    [("Probably", "probably"), ("Definitely", "definitely")]
)

# multiselect
gtui.multiselect(
    "Which of the following applies to your favorite train?",
    [
        ("I wish it could drift", "wish", True), # toggled on by default
        ("I'm sad that it can't drift", "sadness", False),
        ("It's really nice that it can drift", "happiness", False)
    ]
)

# multiselect with rules
gtui.multiselect(
    "Pick your stack",
    [
        gtui.Option("Core", "core"),
        gtui.Option("Analytics", "analytics", requires={"core"}),
        gtui.Option("Legacy mode", "legacy", excludes={"core"}),
    ]
)

# spinners
with gtui.spinner("Preparing for ethical dilemmas...") as s:
    time.sleep(1)
    s.update("Installing drift capabilities...")
    time.sleep(1)
    s.update("Updating Terms of Use...")
    time.sleep(1)
    s.done("Drift ready")  # leaves a [+] success line on exit
    # on exception, s.fail("message") leaves a [!] error line instead

# status messages
gtui.warn("Aristoteles disliked this") # info, step, success, warn or error

Finally, wrap up with an outro:

gtui.outro("That's all, folks!")

There's a bit more available, eg. input validation. See the example if you want to dive deeper.

API

Function Purpose
intro(title) / outro(msg) / section(title) frames
note(message, title=...) multi-line block (e.g. a confirmation summary)
text(label, default="") single-line input
password(label, mask="·") masked input; mask="" hides length entirely
confirm(label, default=True) y/n prompt
select(label, options) single-choice picker; Option(..., disabled=True) skips navigation
multiselect(label, options) multi-choice picker with optional requires / excludes rules; Option(..., disabled=True) is un-toggleable
spinner(label) threaded spinner context manager; .done() / .fail() leave a final status line
info / step / success / warn / error prefixed status lines

All prompts accept an optional console= kwarg if you want to inject your own Rich Console.

When multiselect() rules are used, referenced option values must be unique.

Platforms

Linux, macOS, and Windows (uses msvcrt for raw input on Windows, termios/tty elsewhere).

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

griphtui-0.2.1.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

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

griphtui-0.2.1-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file griphtui-0.2.1.tar.gz.

File metadata

  • Download URL: griphtui-0.2.1.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for griphtui-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0d95db7978b7349ef73b33bc75ca5799235cc1c49dd76215cc89a78094ef0896
MD5 197b4776e20c8801887e96a58c7a38c9
BLAKE2b-256 c26dc216cd8ddd15f34d768fa909edc5afaf8fcac72cfd6bdd343ee9458d7c09

See more details on using hashes here.

Provenance

The following attestation bundles were made for griphtui-0.2.1.tar.gz:

Publisher: publish.yml on bhark/griphTUI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file griphtui-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: griphtui-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for griphtui-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53094ddb793ab635b9506e90c493c77034b97af5c4c705de374ab90265103d3c
MD5 9ef68a04d26e1aca37b9b5a19c140021
BLAKE2b-256 dce565966025697867a9e8f32ca9ba0dda4d94835192280116cecf777d6c4026

See more details on using hashes here.

Provenance

The following attestation bundles were made for griphtui-0.2.1-py3-none-any.whl:

Publisher: publish.yml on bhark/griphTUI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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