progress

thread safe progress bar and spinner library
git clone git://brookjeynes.dev/bjeynes/progress.git
Log | Files | Refs | README | LICENSE

complex.zig (1382B)


      1 const std = @import("std");
      2 const ProgressBar = @import("progress").Bar;
      3 
      4 pub fn main(init: std.process.Init) !void {
      5     var stdout_buf: [4096]u8 = undefined;
      6     var stdout_writer = std.Io.File.stdout().writer(init.io, &stdout_buf);
      7 
      8     var pb1 = ProgressBar.init(28, &stdout_writer, .{
      9         .bar_prefix = '[',
     10         .bar_suffix = ']',
     11         .bar_fill_char = '=',
     12         .description = "Bar 1",
     13         .show_iterations = true,
     14         .show_percentage = true,
     15         .width = 60,
     16         .colour = .Blue,
     17     });
     18 
     19     var pb2 = ProgressBar.init(15, &stdout_writer, .{
     20         .bar_prefix = '|',
     21         .bar_suffix = '|',
     22         .bar_fill_char = '━',
     23         .description = "Bar 2",
     24         .show_iterations = true,
     25         .show_percentage = true,
     26         .width = 100,
     27         .show_background = true,
     28         .colour = .{ .RGB = .{ .r = 255, .g = 0, .b = 127 } },
     29         .bg_colour = .{ .RGB = .{ .r = 120, .g = 0, .b = 127 } },
     30     });
     31     const progress_bars: [2]*ProgressBar = .{ &pb1, &pb2 };
     32 
     33     for (progress_bars, 0..) |pb, i| {
     34         while (!pb.isFinished()) {
     35             pb.add(1);
     36             try pb.render();
     37 
     38             if (i == 0) {
     39                 if (pb.current_progress == 14) pb.updateDescription("Bar 1: nearly there");
     40             }
     41 
     42             try std.Io.sleep(init.io, std.Io.Duration.fromMilliseconds(150), .awake);
     43         }
     44     }
     45 }