add loading bar

This commit is contained in:
smayzy 2025-12-19 13:11:20 +01:00
parent 82f5a40a87
commit b38ad16d13

View File

@ -8,7 +8,7 @@ void get_data(int *speed, int *capacity)
*capacity = rand() % 101;
}
void update(WINDOW *win, int data)
void update(WINDOW *win, int data, int max)
{
int win_y, win_x;
char message[64];
@ -18,7 +18,12 @@ void update(WINDOW *win, int data)
box(win, 0, 0);
getmaxyx(win, win_y, win_x);
mvwprintw(win, win_y/2, win_x/2 - strlen(message)/2, "%s", message);
mvwprintw(win, win_y/2, win_x/4 - strlen(message)/2, "%s", message);
mvwprintw(win, win_y/2, win_x/2, "x");
int i;
for (i = 0; i < ((data * (win_x / 3)) / max); i++) {
wprintw(win, "x");
}
wrefresh(win);
}
@ -28,7 +33,7 @@ int main()
noecho();
cbreak();
curs_set(0);
nodelay(stdscr, true);
nodelay(stdscr, TRUE);
int y,x;
getmaxyx(stdscr, y, x);
@ -51,8 +56,8 @@ int main()
while(ch == ERR)
{
get_data(&speed, &capacity);
update(top_win, speed);
update(bottom_win, capacity);
update(top_win, speed, 200);
update(bottom_win, capacity, 100);
ch = getch();
};