Skip to main content

module util::Progress

rascal-0.40.16

Usage

import util::Progress;

Dependencies

import String;
import IO;
import util::Math;

function progressBar

This progressbar can be used in terminal applications to show the progress of some process in the terminal.

tuple[void(str) report, void() finished] progressBar(int total, str prefix = "Progress:", int length = 50, int limit = total, str fill = "\u2588", str unfill = "-", str printEnd = "\r")

The total number of steps is the only required parameter to be passed in. All other parameters are optional.

  • prefix is the string that is displayed in front of the progress bar (default "").

  • length is the length (number of characters) of the displayed bar (default 50).

  • limit allows for the throtteling of the number of times the progress bar is printed. For instance if the total is 1000 and the limit is set to 100 then the progress bar will be updated every 10 iterations.

  • fill is the character used for the percentage used (default "\u2588").

  • unfill is the character used for the unused part (default "-").

  • printEnd is the character used at the end of the line (default "\r").

    The return is a tuple with 2 functions, the report and the finished function.

  • report(str suffix) needs to be called for every iteration update. The suffix is displayed after the progressbar and can differ per iteration

  • finished() can be called at the end of the iteration to add a new line to the terminal

    It is inspired on the progressbar described here: https://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console

function spinner

Simple spinner to display progress for some terminal process for which the total number of steps is not known.

void (str) spinner(str prefix = " ", str printEnd = "\r")

prefix - Contains the string displayed in front the spinner (default " ").

It returns a function that can be called to make the spinner spin one rotation. This function takes a suffix string parameter that will be displayed behind the spinner