120 lines
2.4 KiB
C
120 lines
2.4 KiB
C
|
/*
|
||
|
* ecran.c
|
||
|
* -------
|
||
|
*
|
||
|
* Maybe, one day, we can have colors...
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
#include "ecoute.h"
|
||
|
|
||
|
/*==------------------------------------------------------------------==*/
|
||
|
/*
|
||
|
* global variables
|
||
|
*/
|
||
|
int couleur = 0;
|
||
|
/*==------------------------------------------------------------------==*/
|
||
|
void bordure(WINDOW * w, int flag)
|
||
|
{
|
||
|
if (flag)
|
||
|
box(w, 0, 0);
|
||
|
else
|
||
|
wborder(w, '|', '|', '-', '-', '+', '+', '+', '+');
|
||
|
}
|
||
|
/*==------------------------------------------------------------------==*/
|
||
|
int alerte(char *texte, int flag)
|
||
|
{
|
||
|
/*
|
||
|
* this func is a stub. real implementation for the next release.
|
||
|
*/
|
||
|
return -1;
|
||
|
}
|
||
|
/*==------------------------------------------------------------------==*/
|
||
|
#define T_MAX_PB 90
|
||
|
int progress_bar(WINDOW *win, long val, long maxval, int type)
|
||
|
{
|
||
|
int foo, largeur;
|
||
|
int larg_win, haut_win;
|
||
|
int curseur;
|
||
|
char chaine[T_MAX_PB+1];
|
||
|
|
||
|
/*
|
||
|
* premier defi, retrouver largeur et hauteur de la fenetre
|
||
|
*/
|
||
|
larg_win = getmaxx(win);
|
||
|
haut_win = getmaxy(win);
|
||
|
|
||
|
largeur = (T_MAX_PB<larg_win ? T_MAX_PB : larg_win) - 6;
|
||
|
|
||
|
#if DEBUG_LEVEL > 1
|
||
|
sprintf(chaine, "> x %-4d y %-4d l %-4d <", larg_win, haut_win, largeur);
|
||
|
mvwaddstr(win, 1, 1, chaine);
|
||
|
wrefresh(win);
|
||
|
#endif
|
||
|
|
||
|
curseur = (val*largeur) / maxval;
|
||
|
|
||
|
#if DEBUG_LEVEL > 1
|
||
|
fprintf(stderr, "maxval %ld val %ld largeur %d curseur %d\n",
|
||
|
maxval, val, largeur, curseur);
|
||
|
#endif
|
||
|
|
||
|
chaine[0] = '[', chaine[largeur] = ']', chaine[largeur+1] = '\0';
|
||
|
for (foo=1; foo<largeur; foo++)
|
||
|
{
|
||
|
if (foo<curseur)
|
||
|
chaine[foo] = 'o';
|
||
|
else
|
||
|
chaine[foo] = '-';
|
||
|
}
|
||
|
mvwaddstr(win, haut_win-3, 2, chaine);
|
||
|
wrefresh(win);
|
||
|
|
||
|
foo = 42;
|
||
|
return foo;
|
||
|
}
|
||
|
/*==------------------------------------------------------------------==*/
|
||
|
void termine_ecran(void)
|
||
|
{
|
||
|
endwin(); exit(0);
|
||
|
}
|
||
|
/*==------------------------------------------------------------------==*/
|
||
|
void prepare_ecran(void)
|
||
|
{
|
||
|
|
||
|
#if DEBUG_LEVEL
|
||
|
fprintf(stderr, ">>> %s ( )\n", __func__);
|
||
|
#endif
|
||
|
|
||
|
initscr();
|
||
|
|
||
|
if (has_colors())
|
||
|
{
|
||
|
use_default_colors();
|
||
|
couleur = 1;
|
||
|
}
|
||
|
|
||
|
nonl(); cbreak(); noecho();
|
||
|
|
||
|
keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
|
||
|
|
||
|
bordure(stdscr, 1);
|
||
|
standout();
|
||
|
mvaddstr(0, 5, "{ Ecoute v " VERSION " - by tTh }");
|
||
|
mvaddstr(LINES-1, 5, "{ hit '?' for help, 'Q' for quit }");
|
||
|
standend();
|
||
|
refresh();
|
||
|
|
||
|
atexit(termine_ecran);
|
||
|
}
|
||
|
/*==------------------------------------------------------------------==*/
|
||
|
void say_goodbye(void)
|
||
|
{
|
||
|
bordure(stdscr, 0);
|
||
|
wrefresh(stdscr);
|
||
|
}
|
||
|
/*==------------------------------------------------------------------==*/
|