CLI tool to generate UI code for HTML, ImGui, or Curses from a simple config file
Project description
📘 Stencil
stencil is a lightweight CLI tool that generates UI code for various backends from a single YAML or JSON configuration file. Describe your UI once and let stencil generate the boilerplate for web, desktop, or terminal applications.
✨ Features
- Multi-Backend Support: Generate UIs for HTML, ImGui (desktop), and Curses (terminal).
- Simple Configuration: Define your UI with a straightforward YAML or JSON file.
- Extensible: Designed to be easily adaptable to new UI toolkits and frameworks.
- Hot-Reload: Automatically regenerate your UI when the configuration file changes.
- Zero Setup: Install and run. It's that simple.
📦 Installation
pip install stencil-ui
Requires Python 3.9+
🚀 Usage
1. Initialize Your Project
Create a default stencil.yaml in your current directory:
stencil init
This will give you a well-commented starting point for your UI configuration.
2. Generate Your UI
Use the generate command to create your UI from the stencil.yaml file.
stencil generate
By default, stencil generates an HTML file. You can specify a different backend using the --backend or -b flag:
# Generate an HTML file (index.html)
stencil generate -b html
# Generate an ImGui desktop application (ui.py)
stencil generate -b imgui
# Generate a Curses terminal application (ui.py)
stencil generate -b curses
3. Watch for Changes
For rapid development, you can use the --watch flag to automatically regenerate the UI whenever you save changes to your stencil.yaml:
stencil generate --watch
This is especially useful with a live-reload server for web development.
⚙️ Configuration
stencil looks for a stencil.yaml or stencil.json file in the current directory. Here's a simple example:
# stencil.yaml
app:
- title: "My App"
- text: "Welcome to Stencil!"
- separator
- input:
label: "Your Name"
placeholder: "Enter your name"
- button:
label: "Submit"
callback: "submit_name"
Supported Elements
| Element | YAML Example | HTML Output | ImGui Output | Curses Output |
|---|---|---|---|---|
title |
- title: "My App" |
<h1> & <title> |
Window Title | Centered bold text |
text |
- text: "Hello!" |
<p> |
imgui.text |
Centered text |
button |
- button: {label: "Click", callback: "on_click"} |
<button> |
imgui.button |
[ Click ] |
separator |
- separator |
<hr> |
imgui.separator |
────────── |
input |
- input: {label: "Name", placeholder: "Your name"} |
<input type="text"> |
imgui.input_text |
Name: [ ] |
🖼 Example Outputs
Based on the configuration example above, here's what stencil will generate for each backend:
- HTML (
-b html): Creates anindex.htmlfile with basic styling and amain.jsfile with JavaScript stubs for your callbacks. - ImGui (
-b imgui): Creates aui.pyfile. Runpython ui.pyto launch a native desktop window with your UI elements. Callbacks are generated as placeholder Python functions. - Curses (
-b curses): Creates aui.pyfile. Runpython ui.pyin your terminal to launch a text-based UI. Use Tab to navigate and Enter to press buttons.
🛠 Development
Clone the repository and install it in editable mode:
git clone https://github.com/your-username/stencil.git
cd stencil
pip install -e .
📜 License
This project is licensed under the MIT License.
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 stencil_ui-0.2.2.tar.gz.
File metadata
- Download URL: stencil_ui-0.2.2.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06e2ba3d00394c2d3ef53a31a650d04494a5989a3b08da93ec6b99f0849ee6c0
|
|
| MD5 |
be63914d58c71a41bd52c2eb5b2d818b
|
|
| BLAKE2b-256 |
c4981a28e9a44785b9154ea6f91bfee29f48172d7873ff7b39fb375c42cdb482
|
File details
Details for the file stencil_ui-0.2.2-py3-none-any.whl.
File metadata
- Download URL: stencil_ui-0.2.2-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
162410e8797509c489559c17662176f4ae4b090cce58b5182171e9a9ed5acdf7
|
|
| MD5 |
26e9d73d7f9ec965862556e4453fe979
|
|
| BLAKE2b-256 |
0f485f8b67d9cb7bb151c9a67b838d870e12bf2c89166fae9db2c00b2722557a
|