wget2: Progress Display Functions

| wget2 2.0.0

- Main Page
- Modules
- Data Structures
- Files

Data Structures | Enumerations | Functions
Progress Display Functions

## Data Structures
struct | bar_slot
struct | wget_bar_st

## Enumerations
enum | BAR_SIZES { BAR_FILENAME_SIZE = 20 , BAR_RATIO_SIZE = 3 , BAR_METER_COST = 2 , BAR_DOWNBYTES_SIZE = 8 , BAR_SPEED_SIZE = 8 }
enum | BAR_DECOR_SIZE { BAR_DECOR_COST }
enum | SCREEN_WIDTH { DEFAULT_SCREEN_WIDTH = 70 , MINIMUM_SCREEN_WIDTH = 45 }
enum | bar_slot_status { EMPTY = 0 , DOWNLOADING = 1 , COMPLETE = 2 }
enum | BAR_SETTINGS { SPEED_RING_SIZE = 24 }

## Functions
wget_bar * | wget_bar_init (wget_bar *bar, int nslots)
void | wget_bar_set_slots (wget_bar *bar, int nslots)
void | wget_bar_slot_begin (wget_bar *bar, int slot, const char *filename, int new_file, ssize_t file_size)
void | wget_bar_slot_downloaded (wget_bar *bar, int slot, size_t nbytes)
void | wget_bar_slot_deregister (wget_bar *bar, int slot)
void | wget_bar_update (wget_bar *bar)
void | wget_bar_deinit (wget_bar *bar)
void | wget_bar_free (wget_bar **bar)
void | wget_bar_print (wget_bar *bar, int slot, const char *display)
void | wget_bar_vprintf (wget_bar *bar, int slot, const char *fmt, va_list args)
void | wget_bar_printf (wget_bar *bar, int slot, const char *fmt,...)
void | wget_bar_screen_resized (void)
void | wget_bar_write_line (wget_bar *bar, const char *buf, size_t len)
void | wget_bar_set_speed_type (wget_report_speed type)

## Detailed Description

Methods for creating and printing a progress bar display.

## Enumeration Type Documentation

## ◆ BAR_SETTINGS

enum BAR_SETTINGS

The settings for drawing the progress bar.

This includes things like how often it is updated, how many values are stored in the speed ring, etc.

Enumerator
SPEED_RING_SIZE | The number of values to store in the speed ring.

## Function Documentation

## ◆ wget_bar_init()

wget_bar* wget_bar_init | ( | wget_bar * | bar,
|  | int | nslots
| ) |  |

Parameters

  [in] | bar | Pointer to a `wget_bar` object
  [in] | nslots | Number of progress bars

Returns
  Pointer to a `wget_bar` object

Initialize a new progress bar instance. If `bar` is a NULL pointer, it will be allocated on the heap and a pointer to the newly allocated memory will be returned. To free this memory, call either the wget_bar_deinit() or wget_bar_free() functions based on your needs.

`nslots` is the number of screen lines to reserve for printing the progress bars. This may be any number, but you generally want at least as many slots as there are downloader threads.

## ◆ wget_bar_set_slots()

void wget_bar_set_slots | ( | wget_bar * | bar,
|  | int | nslots
| ) |  |

Parameters

  [in] | bar | Pointer to a wget_bar object
  [in] | nslots | The new number of progress bars that should be drawn

Update the number of progress bar lines that are drawn on the screen. This is useful when the number of downloader threads changes dynamically or to change the number of reserved lines. Calling this function will immediately reserve `nslots` lines on the screen. However if `nslots` is lower than the existing value, nothing will be done.

## ◆ wget_bar_slot_begin()

void wget_bar_slot_begin | ( | wget_bar * | bar,
|  | int | slot,
|  | const char * | filename,
|  | int | new_file,
|  | ssize_t | file_size
| ) |  |

Parameters

  [in] | bar | Pointer to a wget_bar object
  [in] | slot | The slot number to use
  [in] | filename | The file name to display in the given `slot`
  [in] | new_file | if this is the start of a download of the body of a new file
  [in] | file_size | The file size that would be 100%

Initialize the given `slot` of the `bar` object with it's (file) name to display and the (file) size to be assumed 100%.

## ◆ wget_bar_slot_downloaded()

void wget_bar_slot_downloaded | ( | wget_bar * | bar,
|  | int | slot,
|  | size_t | nbytes
| ) |  |

Parameters

  [in] | bar | Pointer to a wget_bar object
  [in] | slot | The slot number to use
  [in] | nbytes | The number of bytes downloaded since the last invocation of this function

Set the current number of bytes for `slot` for the next update of the bar/slot.

## ◆ wget_bar_slot_deregister()

void wget_bar_slot_deregister | ( | wget_bar * | bar,
|  | int | slot
| ) |  |

Parameters

  [in] | bar | Pointer to a wget_bar object
  [in] | slot | The slot number to use

Redraw the given `slot` as being completed.

## ◆ wget_bar_update()

void wget_bar_update | ( | wget_bar * | bar | ) |

Parameters

  [in] | bar | Pointer to a wget_bar object

Redraw the parts of the `bar` that have been changed so far.

## ◆ wget_bar_deinit()

void wget_bar_deinit | ( | wget_bar * | bar | ) |

Parameters

  [in] | bar | Pointer to `wget_bar`

Free the various progress bar data structures without freeing `bar` itself.

## ◆ wget_bar_free()

void wget_bar_free | ( | wget_bar ** | bar | ) |

Parameters

  [in] | bar | Pointer to `wget_bar`

Free the various progress bar data structures including the `bar` pointer itself.

## ◆ wget_bar_print()

void wget_bar_print | ( | wget_bar * | bar,
|  | int | slot,
|  | const char * | display
| ) |  |

Parameters

  [in] | bar | Pointer to `wget_bar`
  [in] | slot | The slot number to use
  [in] | display | The string to be displayed in the given slot

Displays the `display` string in the given `slot`.

## ◆ wget_bar_vprintf()

void wget_bar_vprintf | ( | wget_bar * | bar,
|  | int | slot,
|  | const char * | fmt,
|  | va_list | args
| ) |  |

Parameters

  [in] | bar | Pointer to `wget_bar`
  [in] | slot | The slot number to use
  [in] | fmt | Printf-like format to build the display string
  [in] | args | Arguments matching the `fmt` format string

Displays the `string` build using the printf-style `fmt` and `args`.

## ◆ wget_bar_printf()

void wget_bar_printf | ( | wget_bar * | bar,
|  | int | slot,
|  | const char * | fmt,
|  |  | ...
| ) |  |

Parameters

  [in] | bar | Pointer to `wget_bar`
  [in] | slot | The slot number to use
  [in] | fmt | Printf-like format to build the display string
  [in] | ... | List of arguments to match `fmt`

Displays the `string` build using the printf-style `fmt` and the given arguments.

## ◆ wget_bar_screen_resized()

void wget_bar_screen_resized | ( | void |  | ) |

Call this function when a resize of the screen / console has been detected.

## ◆ wget_bar_write_line()

void wget_bar_write_line | ( | wget_bar * | bar,
|  | const char * | buf,
|  | size_t | len
| ) |  |

Parameters

  [in] | bar | Pointer to `wget_bar`
  | buf | Pointer to buffer to be displayed
  | len | Number of bytes to be displayed

Write 'above' the progress bar area, scrolls screen one line up if needed. Currently used by Wget2 to display error messages in color red.

This function needs a redesign to be useful for general purposes.

## ◆ wget_bar_set_speed_type()

void wget_bar_set_speed_type | ( | wget_report_speed | type | ) |

Parameters

  type | Report speed type

Set the progress bar report speed type to WGET_REPORT_SPEED_BYTES or WGET_REPORT_SPEED_BITS.

Default is WGET_REPORT_SPEED_BYTES.