Categories
Libraries
Parser
  • Github CLI
  • SSH
  • HTTPS
Clone Repo

zig-prompter

zig-prompter is a lightweight and flexible library for building and managing interactive text-based prompts in the Zig programming language. 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:

zig fetch --save git+https://github.com/GabrieleInvernizzi/zig-prompter/

Update your build.zig file to include the dependency:

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:

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 directory.

Features

  • String prompt
  • Interactive option selection prompt
  • Confirmation prompt
  • Password prompt
  • Input validation
  • 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.

About
zig-prompter is a lightweight and flexible library for building and managing interactive text-based prompts.
Last Commit
2025-01-12
Latest Release
Latest Release Date
Created
2024-12-11