Skip to main content

A Python library for creating Terminal User Interfaces using curses

Reason this release was yanked:

accidently unyanked

Project description

tuilib: Your Pythonic Terminal UI Companion

What is tuilib?

tuilib is a Python library designed to simplify the creation of Terminal User Interfaces (TUIs). It provides a high-level, intuitive, and Pythonic way to build interactive command-line applications. Instead of wrestling with low-level curses functions, tuilib allows you to define your UI with Python objects and methods.

Why tuilib?

I created tuilib because I found that existing TUI libraries for Python often felt cumbersome and not very "Pythonic". Many required developers to manage low-level details, making the development process more complex than it needed to be. There was a need for a library that allowed Python developers to quickly and easily create TUIs using familiar Python concepts. tuilib aims to fill that gap by providing:

  • A High-Level API: Focus on defining your UI's structure and behavior, not on low-level terminal manipulation.
  • Intuitive Design: Create UI elements and manage interactions in a way that feels natural to Python programmers.
  • Pythonic Conventions: Embrace Python's principles of readability and simplicity.

Who Benefits from tuilib?

tuilib is ideal for Python programmers who want to:

  • Build interactive command-line tools.
  • Create user-friendly interfaces for scripts and applications.
  • Develop terminal-based dashboards or monitoring tools.
  • Quickly prototype and iterate on command-line UI ideas.
  • Avoid the complexities of lower-level TUI libraries.

Essentially, any Python developer who needs a TUI and values a clean, efficient, and Pythonic approach will find tuilib beneficial.

How Does It Work?

tuilib provides a set of classes and functions that represent common TUI elements, such as windows, layouts, and input fields. Here's a simplified overview:

  1. Initialization: You initialize the library, which sets up the terminal environment.
  2. Layout Definition: You define the structure of your UI using layout managers. These managers control how UI elements are arranged within the terminal window.
  3. Widget Creation: You create UI elements (widgets) like text boxes, input fields, buttons, and more.
  4. Event Handling: You define how the application should respond to user input (e.g., key presses, mouse clicks).
  5. Main Loop: tuilib handles the main loop, which listens for user input, updates the UI, and redraws the screen as needed.

Under the hood, tuilib likely uses a more established library (like curses or another backend) to interact with the terminal. However, tuilib abstracts away these low-level details, providing a much simpler interface.

Example Cases

Here are some example cases to illustrate what you can do with tuilib:

  • Number Selection:

    from tuilib import tui
    def main(stdscr):
        num:int = tui.number_selector(stdscr,0,0,10) #starts at 0, minimum 0, maximum 10
        tui.func_exit(stdscr)
        print(num)
    tui.main(main)
    

    This example demonstrates how to create a number selector, allowing the user to choose a number within a specified range.

  • List Selection:

    from tuilib import tui
    def main(stdscr):
        options = ["banana","grape","cherry","apple"]
        choice = tui.list_selector(stdscr,options)
        tui.func_exit(stdscr)
        print("you chose",choice)
    tui.main(main)
    

    This example shows how to present the user with a list of options and retrieve their selection.

  • Real-time Input:

    from tuilib import tui
    def main(stdscr):
        name:str = tui.real_time_input(stdscr,"what is your name?: ")
        tui.func_exit(stdscr)
        print("hello",name)
    tui.main(main)
    

    This example illustrates how to capture user input in real-time and display it in the terminal.

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

tuilib-3.1.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

tuilib-3.1.0.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file tuilib-3.1.0.1.tar.gz.

File metadata

  • Download URL: tuilib-3.1.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for tuilib-3.1.0.1.tar.gz
Algorithm Hash digest
SHA256 d269d329b23aee836300f53c93d4ce8adff37c536a5e765e33e3bbe2f02da2f9
MD5 262def2214f16d2bacab617d1937ca1c
BLAKE2b-256 b91f110b5c9ccfa9f146ab2459cae7bd1befa39bb9343af9922d2827d0e0032d

See more details on using hashes here.

File details

Details for the file tuilib-3.1.0.1-py3-none-any.whl.

File metadata

  • Download URL: tuilib-3.1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for tuilib-3.1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89f04d94c00cb4564cf003e32d707bf90b55ddaec845a2fa12e1849a05349404
MD5 36b4024e9d755f62385fc7bd38ec2b80
BLAKE2b-256 8ae285677639d0de4fffd5efa9f55a30fc527f2ff48563759a673ea3ad6867ba

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