All Projects → jwerle → Progress.c

jwerle / Progress.c

Progress display lib for c

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Progress.c

Mordant
Full-featured text styling for Kotlin command-line applications
Stars: ✭ 382 (+470.15%)
Mutual labels:  terminal, ansi
Imgcat
It's like cat, but for images.
Stars: ✭ 577 (+761.19%)
Mutual labels:  terminal, ansi
Colorful
Terminal string styling done right, in Python 🐍 🎉
Stars: ✭ 456 (+580.6%)
Mutual labels:  terminal, ansi
Paint
Ruby gem for ANSI terminal colors 🎨︎ VERY FAST
Stars: ✭ 317 (+373.13%)
Mutual labels:  terminal, ansi
Unicute
💙 Cute Unicode symbols. Make the terminal GREAT AGAIN
Stars: ✭ 35 (-47.76%)
Mutual labels:  terminal, ansi
Tqdm
A Fast, Extensible Progress Bar for Python and CLI
Stars: ✭ 20,632 (+30694.03%)
Mutual labels:  terminal, progress
Termenv
Advanced ANSI style & color support for your terminal applications
Stars: ✭ 555 (+728.36%)
Mutual labels:  terminal, ansi
Alive Progress
A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
Stars: ✭ 2,940 (+4288.06%)
Mutual labels:  terminal, progress
Pixterm
Draw images in your ANSI terminal with true color
Stars: ✭ 782 (+1067.16%)
Mutual labels:  terminal, ansi
Chafa
📺🗿 Terminal graphics for the 21st century.
Stars: ✭ 774 (+1055.22%)
Mutual labels:  terminal, ansi
Enigma Bbs
ENiGMA½ BBS Software
Stars: ✭ 294 (+338.81%)
Mutual labels:  terminal, ansi
Rang
A Minimal, Header only Modern c++ library for terminal goodies 💄✨
Stars: ✭ 1,080 (+1511.94%)
Mutual labels:  terminal, ansi
Chalk
🖍 Terminal string styling done right
Stars: ✭ 17,566 (+26117.91%)
Mutual labels:  terminal, ansi
Hues
Colored terminal text made easy for Python and happiness.
Stars: ✭ 345 (+414.93%)
Mutual labels:  terminal, ansi
Colorizeswift
Terminal string styling for Swift.
Stars: ✭ 253 (+277.61%)
Mutual labels:  terminal, ansi
Termplay
GitLab: https://gitlab.com/jD91mZM2/termplay
Stars: ✭ 500 (+646.27%)
Mutual labels:  terminal, ansi
Terminal Canvas
Manipulate the cursor in your terminal via high-performant, low-level, canvas-like API
Stars: ✭ 125 (+86.57%)
Mutual labels:  terminal, ansi
Ansiweather
Weather in terminal, with ANSI colors and Unicode symbols
Stars: ✭ 1,663 (+2382.09%)
Mutual labels:  terminal, ansi
Python Progressbar
Progressbar 2 - A progress bar for Python 2 and Python 3 - "pip install progressbar2"
Stars: ✭ 682 (+917.91%)
Mutual labels:  terminal, progress
Colorette
Easily set the color and style of text in the terminal.
Stars: ✭ 1,047 (+1462.69%)
Mutual labels:  terminal, ansi

progress.h

Simple progress bar display for the terminal inspired by node-progress

usage

#include <progress.h>

example

#include <progress.h>

void
on_progress (progress_data_t *data);

int
main (void) {
  progress_t *progress = progress_new(100, 60);
  progress->fmt = "progress [:bar] :percent :elapsed";
   
  // listen for progress
  progress_on(progress, PROGRESS_EVENT_PROGRESS, on_progress);
  
  // tick progress
  progress_tick(progress, 10);
}

void
on_progress (progress_data_t *data) {
  progress_write(data->holder);
}

output

progress [======------------------------------------------------------] 10% 0.0s

usage

setup

Create a new progress_t * pointer with a given int total and progress bar size_t width.

int total = 100;
size_t width = 20;
progress_t *progress = progress_new

format

You can define the output to stdout by setting the char * fmt member on the progress_t * pointer. Available tokens in the format string are:

  • :bar - represents progress bar
  • :percent - represents current progress percent
  • :elapsed - represents current elapsed time in seconds as a float
progress->fmt = "  downloading :percent (:elapsed) :bar";

The characters used to draw the complete and incomplete parts of the progress bar can be set too.

progress->bar_char = ".";
progress->bg_bar_char = " ";

events

Bind function callbacks to events where an progress_event_type_t event is:

  • PROGRESS_EVENT_START - represents an event type for when progress has begun
  • PROGRESS_EVENT_PROGRESS - represents an event type for when progress has ticked
  • PROGRESS_EVENT_END - represents an event type for when progress has completed

A valid callback has the following signature which accepts a progress_data_t * pointer.

void callback (progress_data_t *data);
progress_on(progress, PROGRESS_EVENT_START, on_progress_start);
progress_on(progress, PROGRESS_EVENT_PROGRESS, on_progress);
progress_on(progress, PROGRESS_EVENT_END, on_progress_end);

ticks

To increment progress the progress_t * pointer must be passded to progress_tick. If the total has been met then any function pointer bound to PROGRESS_EVENT_END will be called in the order they were bound.

progress_tick(progress, 42);

value

to set the progress bar to specific value you can call. If the total has been met then any function pointer bound to PROGRESS_EVENT_END will be called in the order they were bound.

progress_value(progress, 20);

inspect

You can inspect your progress_t * struct with progress_inspect(progress);.

progress_inspect(progress);

output

#progress =>
    .value: 100
    .total: 100
    .listener_count: 3
    .elapsed: 2.000000
    .start: 1378344826
    .width: 60
    .started: true
    .finished: true
    .bar_char: "="
    .bg_bar_char: "-"
    .fmt: "progress [:bar] :percent :elapsed"
    .listeners[3]

api

progress_new(total, width);

progress_t *
progress_new (int total, size_t width);

Initializes a new progress_t * pointer with a total and width.

example

progress_t *progress = progress_new(100, 20);

progress_event_new(type);

progress_event_t *
progress_event_new(progress_event_type_t type);

Initializes a new progress_event_t * pointer with an event type where type is of enum progress_event_types.

example

progress_event_t * = progress_event_new(PROGRESS_EVENT_PROGRESS);

progress_event_listener_new(type, cb);

progress_event_listener_t *
progress_event_listener_new (progress_event_t *event, progress_cb_t cb);

Initializes a new progress_event_listener_t * pointer bound to an event with a given callback progress_cb_t function pointer.

example

...

progress_event_t *event = progress_event_new(PROGRESS_EVENT_PROGRESS);
progress_event_listener_t *listener = progress_event_listener_new(event, onprogress);

...

void
onprogress (progress_data_t *data) {
  printf("value -> %d\n", data->value);
  printf("ts -> %d\n", data->ts);
}

progress_event_listener_free(listener);

void
progress_event_listener_free (progress_event_listener_t *listener);

Frees a progress_event_listener_t * pointer

example

progress_event_listener_free(listener);

progress_data_new(holder, value);

Initializes a new progress_data_t * pointer

progress_data_t *
progress_data_new (progress_t *holder, int value);

example

progress_data_t * data = progress_data_new(progress, 32);

progress_on(progress, type, cb);

bool
progress_on (progress_t *progress, progress_event_type_t type, progress_cb_t cb);

Binds a progress_cb_t * pointer to a progress_event_t pointer on a progress_t pointer.

example

progress_on(progress, PROGRESS_EVENT_PROGRESS, onprogress);

progress_emit(progress, event, data);

Emits an event with data.

bool
progress_emit (progress_t *progress, progress_event_t *event, progress_data_t *data);

example

progress_event_t *event = progress_event_new(PROGRESS_EVENT_START);
progress_data_t *data = progres_data_new(46);
progress_emit(progress, event, data);

progress_tick(progress, value);

Increments progress by a given value.

bool
progress_tick (progress_t *progress, int value);

example

progress_tick(progress, 16);

progress_value(progress, value);

set progress value

bool
progress_value (progress_t *progress, int value);

example

progress_value(progress, 16);

progress_write(progress);

Draws the progress bar to stdout.

void
progress_write (progress_t *progress);

example

progress_write(progress);
// progress [======------------------------------------------------------] 10% 0.0s

progress_free(progress);

Fress a progress_t * poiinter.

void
progress_free (progress_t *progress);

example

progress_free(progress);

license

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].