HW12/display_bar.h

49 lines
1.4 KiB
C
Raw Normal View History

2020-12-08 02:59:11 +09:00
#include<stdio.h>
#include<time.h>
#include<stdbool.h>
2020-12-14 20:09:12 +09:00
#include<stdarg.h>
2020-12-08 02:59:11 +09:00
#ifndef _DISPLAY_BAR_H_
#define _DISPLAY_BAR_H_
2020-12-14 19:19:49 +09:00
//declare for raw operation
2020-12-08 02:59:11 +09:00
typedef unsigned raw_progress_bar_t;
void lock_scrolled();
void unlock_scrolled();
void add_scrolled_unlocked(unsigned int i);
raw_progress_bar_t create_raw_progress_bar();
void RawDisplayProgressBar(raw_progress_bar_t bar,size_t offset,size_t total,const char * filename);
2020-12-14 19:19:49 +09:00
//you should call before using progrees bar.
void ready_progress_bar();
//quit progress bar system.
void quit_progress_bar();
//same as isatty
2020-12-08 02:59:11 +09:00
bool isatty_file(FILE * file);
2020-12-14 20:09:12 +09:00
//After calling ready_progress_bar, you must use following functions on print.
2020-12-08 02:59:11 +09:00
void myd_perror(const char * msg);
2020-12-14 20:30:46 +09:00
/*argument `line` is number of newline created by argument `msg`.
* thread-safe
*/
2020-12-14 19:19:49 +09:00
int myd_vfprintf(int line,FILE * f,const char * msg,va_list arg);
2020-12-14 20:30:46 +09:00
/*argument `line` is number of newline created by argument `msg`.
* thread-safe
*/
2020-12-14 20:09:12 +09:00
int myd_fprintf(int line,FILE * f,const char * msg, ...);
2020-12-08 02:59:11 +09:00
typedef struct {
raw_progress_bar_t bar;
//millisecond unit
int update_rate;
struct timespec last_update;
} progress_bar_t;
2020-12-09 00:14:42 +09:00
//update rate is millsecond unit
2020-12-08 02:59:11 +09:00
void init_progress_bar(progress_bar_t * bar,int update_rate);
2020-12-14 20:09:12 +09:00
/// display progress bar
/// if `sync`, update unconditionally.
2020-12-08 02:59:11 +09:00
void DisplayProgressBar(progress_bar_t * bar,size_t offset,size_t total,const char * filename, bool sync);
#endif