https://github.com/GabrieleInvernizzi/zig-prompter
zig-prompter is a lightweight and flexible library for building and managing interactive text-based prompts.
https://github.com/GabrieleInvernizzi/zig-prompter
cli prompt terminal zig zig-package
Last synced: 6 months ago
JSON representation
zig-prompter is a lightweight and flexible library for building and managing interactive text-based prompts.
- Host: GitHub
- URL: https://github.com/GabrieleInvernizzi/zig-prompter
- Owner: GabrieleInvernizzi
- License: mit
- Created: 2024-12-11T20:13:44.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-11T14:06:43.000Z (8 months ago)
- Last Synced: 2025-07-11T16:36:04.639Z (8 months ago)
- Topics: cli, prompt, terminal, zig, zig-package
- Language: Zig
- Homepage: https://gabrieleinvernizzi.github.io/zig-prompter/
- Size: 64.5 KB
- Stars: 19
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - zig-prompter🗒️A flexible library for building interactive command line prompts
- awesome-zig - GabrieleInvernizzi/zig-prompter - A flexible library for building interactive command line prompts. (Language Essentials / Command Line and Argument Parser)
- awesome - GabrieleInvernizzi/zig-prompter - zig-prompter is a lightweight and flexible library for building and managing interactive text-based prompts. (<a name="Zig"></a>Zig)
README
# zig-prompter
**zig-prompter** is a lightweight and flexible library for building and managing interactive text-based prompts in the [Zig programming language](https://ziglang.org/). Whether you're creating command-line tools, text-based games, or utilities requiring user input, **zig-prompter** simplifies the process with intuitive APIs and a robust feature set.
## Installation
First, add zig-prompter to your `build.zig.zon` file:
```bash
zig fetch --save git+https://github.com/GabrieleInvernizzi/zig-prompter/
```
Update your `build.zig` file to include the dependency:
```zig
const prompter_dep = b.dependency("prompter", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("prompter", prompter_dep.module("prompter"));
```
Here’s an example of using **zig-prompter** to create a simple selection prompt:
```zig
const std = @import("std");
const Prompter = @import("prompter");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const stdout = std.io.getStdOut();
const theme = Prompter.Themes.SimpleTheme{};
var p = Prompter.Prompt.init(allocator, theme.theme());
const opts = [_][]const u8{ "Option 1", "Option 2", "Option 3" };
const sel_opt = try p.option("Select an option", &opts, 1);
if (sel_opt) |o| {
try stdout.writer().print("The selected option was: {s} (idx: {d})\n", .{ opts[o], o });
} else {
try stdout.writer().writeAll("The selection was aborted.\n");
}
}
```
For a more exhaustive example, take a look at the [example](https://github.com/GabrieleInvernizzi/zig-prompter/tree/main/example) directory.
## Features
- [x] String prompt
- [x] Interactive option selection prompt
- [x] Confirmation prompt
- [x] Password prompt
- [x] Input validation
- [x] Advanced support for themes and personalization
- [ ] Include more themes
- [ ] Windows support
## Contributions
Contributions are always welcome and greatly appreciated! Whether it's fixing bugs, adding features, improving documentation, or enhancing examples, your input helps make **zig-prompter** even better. Feel free to open issues to discuss potential improvements or submit pull requests directly.
Thank you for your support!
## Acknowledgments
This library was inspired by the fantastic **Rust** library [Dialoguer](https://github.com/mitsuhiko/dialoguer).