A native python tui library
Project description
Lokutui
Lokutui is a lightweight Python library for building native terminal user interfaces (TUIs) using curses. It provides core screen management, an event system, and a collection of common widgets that can be composed to build interactive text‑based applications.
Installation
Lokutui is distributed via PyPI;
pip install lokutui
Alternatively, include it directly as a dependency in your project or install from source.
Core concepts
Screen
Screen is the entry point for any application. It handles curses initialization, the main loop, input polling, rendering, and event dispatching. Typical usage:
from lokutui.core import Screen
screen = Screen()
# add widgets
# screen.add_widget(my_widget)
screen.run()
The run method accepts an optional initial_setup_callback where you can configure widgets before the loop starts. Call screen.exit() from any handler to terminate the application.
Screen also supports a simple loading overlay and a modal widget you can assign to screen.modal.
Widget
All visual elements inherit from the base Widget class. A widget has position (x, y), optional size (width, height), and visibility. Widgets must implement render(stdscr, max_y, max_x) and may override handle_event(event) to react to input.
Event system
Events are instances of a simple named tuple with type and data. The library provides helpers for creating key, mouse and custom events:
from lokutui.events import create_key_event, CustomEvent
EventDispatcher is a singleton used by the screen to dispatch events to registered handlers. You can register handlers and post events either directly or by using the global queue:
from lokutui.events import EventDispatcher
dispatcher = EventDispatcher()
def on_key(e):
...
dispatcher.register_handler('key', on_key)
Handlers are called for each event type when Screen processes the queue.
Widgets
Lokutui includes a number of built‑in widgets located in lokutui.widgets:
- Label – render static text at a position with optional width and color.
- Box – draw a bordered rectangle.
- Frame – a
Boxwith an optional title. - Button – clickable text; supports focus/highlight and invokes an
on_clickcallback. - TextInput – single‑line editable input field with basic cursor movement and text editing.
- List – scrollable list of strings; arrow keys or
j/kto navigate,ENTERto select. - Select – horizontal chooser cycling through options with left/right or
h/lkeys. - Checkbox – toggleable checkbox with label.
- VStack/HStack – layout containers stacking child widgets vertically or horizontally.
- Dialog – simple yes/no modal dialog.
- FormDialog – multi‑field modal form with save/cancel buttons.
- LogDisplay – scrollable log window for output messages.
- ProgressBar – horizontal progress indicator.
- Chart – very basic line chart using braille characters.
Each widget accepts positioning and sizing arguments, color pair indices for curses attributes, and optional callbacks for interactions (on_click, on_select, on_change, etc.).
Example of building a simple form:
from lokutui.core import Screen
from lokutui.widgets import VStack, Label, TextInput, Button
screen = Screen()
name_input = TextInput(x=2, y=2, width=20)
submit = Button("Submit", x=2, y=4, on_click=lambda: screen.exit())
vstack = VStack([Label("Name:"), name_input, submit], x=1, y=1, spacing=1)
screen.add_widget(vstack)
screen.run()
Extending Lokutui
You can subclass Widget to create custom components. Implement rendering logic and event handling as needed and add instances to the Screen.
Contributing
Contributions are welcome. Please open issues or pull requests in the repository and follow standard Python packaging conventions.
License
MIT
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
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 lokutui-0.1.5.tar.gz.
File metadata
- Download URL: lokutui-0.1.5.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5495b0fa9793b85c4b44d8675dbdd065577b1d8ed08b9f6a300bc26580f72be4
|
|
| MD5 |
08b9a6327c8a97b1beb4d961de222c52
|
|
| BLAKE2b-256 |
23bcb761e3c636438aae1a153748935bd58c44f3a93de0955f709d507860b5c1
|
Provenance
The following attestation bundles were made for lokutui-0.1.5.tar.gz:
Publisher:
workflow.yml on lokutor-ai/lokutui
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lokutui-0.1.5.tar.gz -
Subject digest:
5495b0fa9793b85c4b44d8675dbdd065577b1d8ed08b9f6a300bc26580f72be4 - Sigstore transparency entry: 995635219
- Sigstore integration time:
-
Permalink:
lokutor-ai/lokutui@a7104c4bf216e839186ef8ccc83ab0d6c7a3a34d -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/lokutor-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@a7104c4bf216e839186ef8ccc83ab0d6c7a3a34d -
Trigger Event:
push
-
Statement type:
File details
Details for the file lokutui-0.1.5-py3-none-any.whl.
File metadata
- Download URL: lokutui-0.1.5-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3234d2d38e861f9a42c7e3c0d6b6e36e1576e68ae442d306c1134643fbb74455
|
|
| MD5 |
7837330008ee5c278e4fb21d6a1ef1f2
|
|
| BLAKE2b-256 |
433ad0cd3ae8e863d3bd4854f2f4274b1f59f99424fd3ac04429a71632914a3e
|
Provenance
The following attestation bundles were made for lokutui-0.1.5-py3-none-any.whl:
Publisher:
workflow.yml on lokutor-ai/lokutui
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lokutui-0.1.5-py3-none-any.whl -
Subject digest:
3234d2d38e861f9a42c7e3c0d6b6e36e1576e68ae442d306c1134643fbb74455 - Sigstore transparency entry: 995635252
- Sigstore integration time:
-
Permalink:
lokutor-ai/lokutui@a7104c4bf216e839186ef8ccc83ab0d6c7a3a34d -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/lokutor-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@a7104c4bf216e839186ef8ccc83ab0d6c7a3a34d -
Trigger Event:
push
-
Statement type: