Skip to main content

A Python library for creating Terminal User Interfaces using curses

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-4.0.0.0.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-4.0.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tuilib-4.0.0.0.tar.gz
Algorithm Hash digest
SHA256 73bea3c15e335e2e466e57fcf0a7478da2ad68c99252ba6cd4dc5832ba980ed2
MD5 785b93cc18b7972c0f704dbba355c2ae
BLAKE2b-256 c7cf3bf4466d1f7eeccf2d5776b8c13dc47f428f660b8a7818aaec01e765461b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for tuilib-4.0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b03e8cd7ad78072dc735bb3c64429a8aa6e7840eb4c8fe74afd6c906680d6b1
MD5 e4ae48ba9ad25cdb44882afca243d1ac
BLAKE2b-256 37688041033623ee6e7e12d27ef9bde0e3c797a17c8b87468b9199e765176838

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