Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Created May 30, 2024 01:58
Show Gist options
  • Save andrewrk/24bc1baf3f6fa9f6a0ee2c50f5be4e76 to your computer and use it in GitHub Desktop.
Save andrewrk/24bc1baf3f6fa9f6a0ee2c50f5be4e76 to your computer and use it in GitHub Desktop.
#include "zp.h"
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv) {
zp_node root_node = zp_init();
const char *task_name = "making orange juice";
zp_node sub_node = zp_start(root_node, task_name, strlen(task_name), 5);
for (int i = 0; i < 5; i += 1) {
zp_complete_one(sub_node);
sleep(1);
}
zp_end(sub_node);
zp_end(root_node);
}
#include <stdint.h>
#include <stddef.h>
typedef uint8_t zp_node;
zp_node zp_init(void);
zp_node zp_start(zp_node parent, const char *name_ptr, size_t name_len, size_t estimated_total);
zp_node zp_end(zp_node node);
zp_node zp_complete_one(zp_node node);
const std = @import("std");
export fn zp_init() std.Progress.Node.OptionalIndex {
return std.Progress.start(.{}).index;
}
export fn zp_start(
parent: std.Progress.Node.OptionalIndex,
name_ptr: [*]const u8,
name_len: usize,
estimated_total_items: usize,
) std.Progress.Node.OptionalIndex {
const node: std.Progress.Node = .{ .index = parent };
return node.start(name_ptr[0..name_len], estimated_total_items).index;
}
export fn zp_end(node_index: std.Progress.Node.OptionalIndex) void {
const node: std.Progress.Node = .{ .index = node_index };
node.end();
}
export fn zp_complete_one(node_index: std.Progress.Node.OptionalIndex) void {
const node: std.Progress.Node = .{ .index = node_index };
node.completeOne();
}
pub const _start = void;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment