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:
- Initialization: You initialize the library, which sets up the terminal environment.
- Layout Definition: You define the structure of your UI using layout managers. These managers control how UI elements are arranged within the terminal window.
- Widget Creation: You create UI elements (widgets) like text boxes, input fields, buttons, and more.
- Event Handling: You define how the application should respond to user input (e.g., key presses, mouse clicks).
- Main Loop:
tuilibhandles 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tuilib-4.1.0.0.tar.gz.
File metadata
- Download URL: tuilib-4.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5634686b91a5051fbd5c849228dd747b6dc2e75f991cb121ad3eec1d9fe2aaa8
|
|
| MD5 |
f92d1d1999f523390510aa153ef03af1
|
|
| BLAKE2b-256 |
89f5f7647e94841e99a6408df6e10b405154d57eb1be60b34a99302d3e0e7e3c
|
File details
Details for the file tuilib-4.1.0.0-py3-none-any.whl.
File metadata
- Download URL: tuilib-4.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c1e0a6ff3245908a292b477c6e234ba32e97f9b24392eaeef4f27c0aa699867
|
|
| MD5 |
bb3b36d0cb96817726b138416f725633
|
|
| BLAKE2b-256 |
51bc92ec6a43f029f5cdc8aafe6ce43c722fed1008b690acbc95a3e54b13b226
|