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-3.2.1.0.tar.gz (3.6 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.2.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tuilib-3.2.1.0.tar.gz
Algorithm Hash digest
SHA256 9267a1b253c919d76f60c8945e2926f39a9ee786c02ac059f463e5a0e58e17d0
MD5 1e5972c2db511bef01717e62d15909c2
BLAKE2b-256 779f6e6603e4d928e9e655cb30c2ef687222563e689884db6dcc8dd71afccc58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tuilib-3.2.1.0-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.2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b043de287a587c853cbb183064fa9ffe4a68289f0333f40ca2548d0b27f460a
MD5 6041a86044bd08d97028f2dcd23576fc
BLAKE2b-256 a531d5e99c9dcae6517bee1a0efaced212cfa559b2d38154e7320738ffb40844

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