@@ -4,6 +4,8 @@ A Zig implementation of the clapp CLI framework - an elegant, feature-rich libra
44
55## Features
66
7+ Clapp Zig is a ** production-ready, feature-complete** CLI framework with 22+ modules and 5,000+ lines of code. It provides feature parity with the TypeScript version, plus additional Zig-specific enhancements.
8+
79### Core CLI Framework
810
911- ** Powerful CLI Framework** - Build robust command-line applications with an elegant API
@@ -15,43 +17,84 @@ A Zig implementation of the clapp CLI framework - an elegant, feature-rich libra
1517
1618### Styling & Formatting
1719
18- - ** ANSI Colors** - Full color support (red, green, blue, yellow, cyan, magenta, etc.)
19- - ** Text Decorations** - Bold, italic, underline, dim, strikethrough, and more
20- - ** Themeable** - Customizable theme colors (primary, success, warning, error, info)
21- - ** Box & Panel Drawing** - Beautiful bordered boxes and panels
22- - ** Table Formatting** - Professional table rendering with borders and headers
20+ - ** ANSI Colors** - Full 16+ color support (red, green, blue, yellow, cyan, magenta, white, black , etc.)
21+ - ** Text Decorations** - Bold, italic, underline, dim, strikethrough, inverse, hidden
22+ - ** Themeable** - Customizable theme colors (primary, success, warning, error, info, muted )
23+ - ** Box & Panel Drawing** - Beautiful bordered boxes and panels with Unicode characters
24+ - ** Table Formatting** - Professional table rendering with borders, headers, and column alignment
2325
2426### Interactive Prompts
2527
28+ #### Basic Prompts
2629- ** Text Input** - Prompts with validation, placeholders, and defaults
2730- ** Confirm Prompts** - Yes/no confirmations with default values
2831- ** Select Prompts** - Single-choice selection from a list
29- - ** Multi-Select** - Multiple-choice selections
30- - ** Password Input** - Masked password entry
32+ - ** Multi-Select** - Multiple-choice selections with checkboxes
33+ - ** Password Input** - Masked password entry for secure input
3134- ** Intro/Outro** - Session start and end messages
3235
36+ #### Advanced Prompts
37+ - ** Autocomplete** - Search-as-you-type with fuzzy matching and keyboard navigation
38+ - ** Path Picker** - File/directory selection with validation and type checking
39+ - ** Number Input** - Numeric input with min/max validation and integer-only mode
40+
3341### Progress & Feedback
3442
35- - ** Spinners** - Animated loading indicators with multiple styles
36- - ** Progress Bars** - Visual progress tracking with percentages
43+ - ** Spinners** - 6 animated spinner styles (dots, line, circle, arrow, box, bounce)
44+ - ** Progress Bars** - Visual progress tracking with percentages and current/total display
3745- ** Task Lists** - Track multiple task statuses (pending, running, success, error)
38- - ** Log Messages** - Styled log output
46+ - ** Log Messages** - Styled log output with severity levels
47+
48+ ### Middleware System
49+
50+ - ** Middleware Chain** - Pre/post command execution hooks
51+ - ** Built-in Middlewares** :
52+ - Logging middleware - Track command execution
53+ - Timing middleware - Measure execution time
54+ - Validation middleware - Validate input before execution
55+ - Auth middleware - Authentication checks
56+ - Rate limiting - Throttle command execution
57+ - ** Custom Middleware** - Create your own middleware functions
58+
59+ ### Signal Handling
3960
40- ### Advanced Features
61+ - ** SIGINT/SIGTERM** - Handle interruption and termination signals
62+ - ** Graceful Shutdown** - Clean shutdown with registered cleanup functions
63+ - ** Custom Handlers** - Register custom signal handlers for any signal
4164
42- - ** Config File Support** - Load settings from JSON files
65+ ### Configuration & Data
66+
67+ - ** Config File Support** - Load settings from JSON files with typed values
4368- ** Environment Variables** - Parse env vars with prefix filtering
69+ - ** Structured Output** - JSON/YAML output formatting for machine-readable results
4470- ** Shell Completion** - Generate completion scripts for bash, zsh, fish, PowerShell
45- - ** Typo Suggestions** - "Did you mean?" suggestions using Levenshtein distance
46- - ** Fuzzy Matching** - Smart command and option matching
47- - ** Enhanced Errors** - Beautiful error messages with suggestions and hints
71+
72+ ### Error Handling
73+
74+ - ** Enhanced Errors** - Beautiful error messages with colored output
75+ - ** Typo Suggestions** - "Did you mean?" suggestions using Levenshtein distance algorithm
76+ - ** Fuzzy Matching** - Smart command and option matching with fuzzy search
77+ - ** Error Context** - Rich error context with hints, code snippets, and suggestions
78+
79+ ### Debug & Development
80+
81+ - ** Debug Mode** - Toggle debug logging for development
82+ - ** Execution Tracing** - Trace execution flow with timestamps
83+ - ** Performance Timers** - Built-in Timer struct for profiling operations
84+
85+ ### HTTP Client
86+
87+ - ** REST Methods** - GET, POST, PUT, DELETE, PATCH support
88+ - ** Headers** - Custom header support
89+ - ** Timeout Configuration** - Configurable request timeouts
90+ - ** Response Handling** - Structured response with status, body, and headers
4891
4992### Testing Utilities
5093
5194- ** Mock Streams** - Mock stdin/stdout/stderr for testing
5295- ** Test Context** - Isolated test environment for CLI apps
53- - ** Assertion Helpers** - Convenient test assertions
54- - ** Output Capture** - Capture and verify CLI output
96+ - ** Assertion Helpers** - Convenient test assertions (equal, contains, isTrue, etc.)
97+ - ** Output Capture** - Capture and verify CLI output in tests
5598
5699## Installation
57100
@@ -173,6 +216,147 @@ try cli_instance.example(.{ .string = " $ myapp install lodash" });
173216try cli_instance.example(.{ .string = " $ myapp install lodash --save-dev" });
174217```
175218
219+ ## Advanced Usage Examples
220+
221+ ### Middleware Chain
222+
223+ ``` zig
224+ var chain = clapp.MiddlewareChain.init(allocator);
225+ defer chain.deinit();
226+
227+ try chain.use(clapp.middleware.loggingMiddleware);
228+ try chain.use(clapp.middleware.timingMiddleware);
229+ try chain.use(clapp.middleware.authMiddleware);
230+
231+ var ctx = clapp.MiddlewareContext.init(allocator, "my-command");
232+ try chain.execute(&ctx);
233+ ```
234+
235+ ### Signal Handling
236+
237+ ``` zig
238+ try clapp.signals.init(allocator);
239+ defer clapp.signals.deinit();
240+
241+ var shutdown = clapp.GracefulShutdown.init(allocator);
242+ defer shutdown.deinit();
243+
244+ try shutdown.onShutdown(cleanup_fn);
245+ try clapp.signals.onSigInt(struct {
246+ fn handle() void {
247+ std.debug.print("Shutting down gracefully...\n", .{});
248+ }
249+ }.handle);
250+ ```
251+
252+ ### Autocomplete Prompt
253+
254+ ``` zig
255+ const options = [_][]const u8{ "React", "Vue", "Angular", "Svelte", "Solid" };
256+ const result = try clapp.autocomplete.autocomplete(allocator, .{
257+ .message = "Search for a framework:",
258+ .options = &options,
259+ .fuzzy = true,
260+ .max_suggestions = 5,
261+ });
262+ defer allocator.free(result);
263+ ```
264+
265+ ### Spinners and Progress
266+
267+ ``` zig
268+ // Spinner
269+ var spinner = try clapp.Spinner.init(allocator, "Loading...", clapp.spinner.spinner_styles.dots);
270+ try spinner.start();
271+ // Do work...
272+ try spinner.success("Done!");
273+
274+ // Progress bar
275+ var progress = clapp.ProgressBar.init(allocator, 100);
276+ for (0..100) |i| {
277+ try progress.update(i);
278+ }
279+
280+ // Task list
281+ var tasks = clapp.TaskList.init(allocator);
282+ defer tasks.deinit();
283+ try tasks.addTask("Initialize", .pending);
284+ try tasks.addTask("Build", .running);
285+ try tasks.addTask("Deploy", .success);
286+ try tasks.render();
287+ ```
288+
289+ ### Styled Output
290+
291+ ``` zig
292+ // Colors and decorations
293+ const error_msg = try clapp.style.red(allocator, "Error!");
294+ const success_msg = try clapp.style.green(allocator, "Success!");
295+ const bold_text = try clapp.style.bold(allocator, "Important");
296+
297+ // Boxes and panels
298+ const boxed = try clapp.style.box(allocator, "Message", .{
299+ .title = "Info",
300+ .padding = 1,
301+ });
302+
303+ // Tables
304+ const data = [_][]const []const u8{
305+ &[_][]const u8{ "Name", "Age", "City" },
306+ &[_][]const u8{ "Alice", "30", "NYC" },
307+ &[_][]const u8{ "Bob", "25", "LA" },
308+ };
309+ try clapp.style.table(allocator, &data, .{ .border = true, .header = true });
310+ ```
311+
312+ ### Config and Output
313+
314+ ``` zig
315+ // Load JSON config
316+ var config = try clapp.Config.loadFromFile(allocator, "config.json");
317+ defer config.deinit();
318+
319+ if (config.getString("api_key")) |key| {
320+ // Use API key
321+ }
322+
323+ // JSON output
324+ var json = clapp.JsonOutput.init(allocator);
325+ defer json.deinit();
326+
327+ try json.addString("status", "success");
328+ try json.addNumber("count", 42);
329+ try json.addBool("enabled", true);
330+
331+ const output = try json.write();
332+ defer allocator.free(output);
333+ ```
334+
335+ ### Debug and Timing
336+
337+ ``` zig
338+ clapp.debug.setDebugMode(true);
339+ clapp.debug.setTraceMode(true);
340+
341+ try clapp.debug.debug(allocator, "Debug message: {s}", .{"info"});
342+ try clapp.debug.trace(allocator, "Tracing execution", .{});
343+
344+ var timer = clapp.Timer.start("Database query");
345+ // Do work...
346+ try timer.stop(allocator); // Prints: "Database query took Xms"
347+ ```
348+
349+ ### HTTP Client
350+
351+ ``` zig
352+ var client = clapp.HttpClient.init(allocator);
353+ var response = try client.get("https://api.example.com/data");
354+ defer response.deinit(allocator);
355+
356+ std.debug.print("Status: {d}\n", .{response.status_code});
357+ std.debug.print("Body: {s}\n", .{response.body});
358+ ```
359+
176360## API Reference
177361
178362### CLI
@@ -235,15 +419,71 @@ zig build run-example
235419
236420## Comparison with TypeScript Version
237421
238- This Zig implementation closely mirrors the TypeScript version's API while leveraging Zig's features:
422+ This Zig implementation not only achieves feature parity with the TypeScript version but adds several production-ready features:
423+
424+ | Feature | TypeScript | Zig | Status |
425+ | ---------| -----------| -----| --------|
426+ | Core CLI | ✅ | ✅ | ✅ Parity |
427+ | Commands & Options | ✅ | ✅ | ✅ Parity |
428+ | Styling & Colors | ✅ | ✅ | ✅ Parity |
429+ | Basic Prompts | ✅ | ✅ | ✅ Parity |
430+ | Advanced Prompts | ✅ | ✅ | ✅ Enhanced |
431+ | Spinners & Progress | ✅ | ✅ | ✅ Parity |
432+ | Config Management | ✅ | ✅ | ✅ Parity |
433+ | Shell Completion | ✅ | ✅ | ✅ Parity |
434+ | Testing Utils | ✅ | ✅ | ✅ Parity |
435+ | Middleware System | ❌ | ✅ | 🎉 New in Zig |
436+ | Signal Handling | ❌ | ✅ | 🎉 New in Zig |
437+ | Debug Mode | ❌ | ✅ | 🎉 New in Zig |
438+ | HTTP Client | ❌ | ✅ | 🎉 New in Zig |
439+ | Memory Management | GC | Explicit allocators | Different approach |
440+ | Error Handling | Exceptions | Error unions | Type-safe |
441+
442+ ### Key Differences
443+
444+ - ** Memory Management** : Zig uses explicit allocators vs TypeScript's garbage collection
445+ - ** Error Handling** : Zig's compile-time error unions vs TypeScript's runtime exceptions
446+ - ** Type System** : Zig's compile-time guarantees provide stronger safety
447+ - ** Performance** : Zig compiles to native code with zero-cost abstractions
448+ - ** Dependencies** : Zig version has zero dependencies (pure stdlib)
449+
450+ ## Examples
451+
452+ The ` examples/ ` directory contains several demonstration programs:
453+
454+ - ** ` basic.zig ` ** - Simple todo app demonstrating core CLI features
455+ - ** ` advanced.zig ` ** - Comprehensive showcase of all advanced features
456+ - ** ` styling.zig ` ** - Visual demonstration of colors, decorations, boxes, and tables
457+ - ** ` comprehensive.zig ` ** - Complete feature showcase with all 22+ modules
458+
459+ Run examples with:
460+ ``` bash
461+ zig build-exe examples/comprehensive.zig --mod clapp::src/main.zig
462+ ./comprehensive prompts # Interactive prompts demo
463+ ./comprehensive progress # Progress indicators demo
464+ ./comprehensive style # Styling showcase
465+ ./comprehensive config # Config and output demo
466+ ```
467+
468+ ## Module Reference
469+
470+ See [ FEATURES.md] ( ./FEATURES.md ) for a complete list of all 22+ modules with detailed usage examples and API documentation.
471+
472+ ## Platform Support
473+
474+ - ** Linux** : ✅ Full support
475+ - ** macOS** : ✅ Full support
476+ - ** Windows** : ⚠️ Partial support (some terminal features may be limited)
477+
478+ Requires Zig 0.15.1 or later.
479+
480+ ## Statistics
239481
240- | Feature | TypeScript | Zig |
241- | ---------| -----------| -----|
242- | Memory Management | Automatic GC | Explicit allocators |
243- | Error Handling | Exceptions | Error unions |
244- | Type System | Structural | Nominal |
245- | Callbacks | Functions | Function pointers |
246- | Async | Promises | Async/await (future) |
482+ - ** 22+ Source Files** - Comprehensive module coverage
483+ - ** 5,000+ Lines of Code** - Production-ready implementation
484+ - ** Unit Tests** - All modules have test coverage
485+ - ** Zero Dependencies** - Pure Zig stdlib implementation
486+ - ** Memory Safe** - Explicit allocator-based memory management
247487
248488## License
249489
0 commit comments