Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/GabrieleInvernizzi/zig-prompter

zig-prompter is a simple but effective way to gather user input from the CLI.
https://github.com/GabrieleInvernizzi/zig-prompter

cli prompt terminal zig

Last synced: about 1 month ago
JSON representation

zig-prompter is a simple but effective way to gather user input from the CLI.

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();

var p = Prompter.Prompt.init(allocator, Prompter.PromptTheme{});

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("\nThe selected option was: {s} (idx: {d})\n", .{ opts[o], o });
} else {
try stdout.writer().writeAll("\nThe 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
- [ ] Advanced support for themes and personalization
- [ ] Windows support

## Contributions
For now the project is in its early stages, still 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).