Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 7 days 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 (2 months ago)
- Default Branch: main
- Last Pushed: 2025-01-12T14:56:46.000Z (about 1 month ago)
- Last Synced: 2025-02-06T06:49:55.194Z (7 days ago)
- Topics: cli, prompt, terminal, zig, zig-package
- Language: Zig
- Homepage: https://gabrieleinvernizzi.github.io/zig-prompter/
- Size: 52.7 KB
- Stars: 14
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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).