AminetAminet
Search:
84451 packages online
About
Recent
Browse
Search
Upload
Setup
Services

dev/c/progress.lha

Mirror:Random
Showing:m68k-amigaosppc-amigaosppc-morphosi386-arosi386-amithlonppc-warpupppc-powerupgeneric
No screenshot available
Short:Simple progress bar display for CLI
Author:Joseph Werle
Uploader:Carsten Larsen (carsten larsen mail com)
Type:dev/c
Version:0.0.4
Architecture:generic; m68k-amigaos
URL:https://github.com/jwerle/progress.c
Date:2022-01-27
Download:http://aminet.net/dev/c/progress.lha - View contents
Readme:http://aminet.net/dev/c/progress.readme
Downloads:737

About

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

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

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);
    }

API

    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

    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 = " ";


    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);

    To increment progress the progress_t* pointer must be passed 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);

    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);

License

    MIT


Contents of dev/c/progress.lha
PERMISSION  UID  GID    PACKED    SIZE  RATIO METHOD CRC     STAMP     NAME
---------- ----------- ------- ------- ------ ---------- ------------ ----------
[unknown]                   14      14 100.0% -lh0- ce95 Jan 27 15:00 progress/.gitignore
[unknown]                  629    1069  58.8% -lh5- 49f3 Jan 27 15:00 progress/LICENSE
[unknown]                  163     228  71.5% -lh5- 43a6 Jan 27 21:31 progress/Makefile
[unknown]                 2244    8270  27.1% -lh5- 50f6 Jan 27 21:01 progress/progress.c
[unknown]                  674    2301  29.3% -lh5- a1f0 Jan 27 15:00 progress/progress.h
[unknown]                 1065    3010  35.4% -lh5- a1c6 Jan 27 21:29 progress/progress.readme
[unknown]                 1702    6176  27.6% -lh5- ad8f Jan 27 15:00 progress/README.md
[unknown]                20312   37288  54.5% -lh5- 61ab Jan 27 21:34 progress/test-progress
[unknown]                  680    3174  21.4% -lh5- bcb3 Jan 27 21:34 progress/test.c
---------- ----------- ------- ------- ------ ---------- ------------ ----------
 Total         9 files   27483   61530  44.7%            Jan 28 04:00

Aminet © 1992-2024 Urban Müller and the Aminet team. Aminet contact address: <aminetaminet net>