Pierosforo

This commit is contained in:
admin committed 2025-10-31 14:34:27 +01:00
1 parent 4d9eba1512
commit 499b3787c6
2 files changed
+100 -13

No files matched your search

+100 -13
View File
@@ -13,18 +13,21 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <ncurses.h> #include <ncurses.h>
// Prototipi // Prototipi
int runMainMenu(); int runMainMenu();
void warning(char *string);
WINDOW *create_newwin(int height, int width, int starty, int startx); WINDOW *create_newwin(int height, int width, int starty, int startx);
void destroy_win(WINDOW *local_win); void destroy_win(WINDOW *local_win);
void print_menu(WINDOW *menu_win, int highlight); void print_menu(WINDOW *menu_win, int y, int x, int highlight);
void word_wrap_print(WINDOW *win, int start_y, int start_x, int max_width, const char *str);
int getCount(); int getCount();
void changeFile(); void changeFile();
int checkIfFileExists(); int checkIfFileExists();
// Costanti // Globali
char productPricesFileLocation[64]="./productPricesSetting.txt"; char productPricesFileLocation[64]="./productPricesSetting.txt";
char countFileLocation[64]="./count.txt"; char countFileLocation[64]="./count.txt";
FILE *productPrices; FILE *productPrices;
@@ -47,6 +50,7 @@ int n_mainMenu = sizeof(mainMenu) / sizeof(char *);
// Funzioni // Funzioni
int main(){ int main(){
initscr(); initscr();
//initialize options
noecho(); noecho();
curs_set(0); curs_set(0);
raw(); raw();
@@ -55,6 +59,13 @@ int main(){
int running = 0; int running = 0;
while(running != 6){ while(running != 6){
running = runMainMenu(); running = runMainMenu();
switch(running) {
case 5:
warning("Questa è una stringa molto lunga . . . Ma anche un test, che ti devo dire, ci proviamo a fare cose che non sono mai state fatte, oltretutto che divertimento ci sarebbe senza esperienze nuove?");
break;
case 6:
break;
}
} }
endwin(); endwin();
@@ -77,37 +88,41 @@ int runMainMenu(){
int c; int c;
keypad(mainWin, TRUE); keypad(mainWin, TRUE);
mvwprintw(mainWin, 1, 2, "Usa le freccette ed invio per scegliere un'opzione!"); mvwprintw(mainWin, 2, 2, "Usa le FRECCETTE ed INVIO per scegliere un'opzione!");
mvwprintw(mainWin, 3, 2, "In alternativa ci sono J e K con SPAZIO!");
refresh(); refresh();
print_menu(mainWin, highlight); print_menu(mainWin, 6, width / 2 - 10, highlight);
while(1) while(1)
{ c = wgetch(mainWin); { c = wgetch(mainWin);
switch(c) switch(c)
{ case KEY_UP: { case KEY_UP:
case 'k':
if(highlight == 1) if(highlight == 1)
highlight = n_mainMenu; highlight = n_mainMenu;
else else
--highlight; --highlight;
break; break;
case KEY_DOWN: case KEY_DOWN:
case 'j':
if(highlight == n_mainMenu) if(highlight == n_mainMenu)
highlight = 1; highlight = 1;
else else
++highlight; ++highlight;
break; break;
case 10: case 10:
case 32:
choice = highlight; choice = highlight;
break; break;
default: default:
mvwprintw(mainWin, height - 2, 2, "Hai premuto il tasto '%c'", c, c); mvprintw(LINES - 2, 1, "Il tasto '%c' non e' un tasto valido . . .", c);
refresh(); refresh();
break; break;
} }
print_menu(mainWin, highlight); print_menu(mainWin, 6, width / 2 - 10, highlight);
if(choice != 0) /* User did a choice come out of the infinite loop */ if(choice != 0) /* User did a choice come out of the infinite loop */
break; break;
} }
mvprintw( LINES - 1 , 0, "Hai premuto il tasto %s\n . . .", mainMenu[choice - 1]); mvprintw( LINES - 2 , 1, "Avvio opzione '%s' . . . ", mainMenu[choice - 1]);
clrtoeol(); clrtoeol();
refresh(); refresh();
destroy_win(mainWin); destroy_win(mainWin);
@@ -115,6 +130,23 @@ int runMainMenu(){
return choice; return choice;
} }
void warning(char *string){
WINDOW *warningWin;
int startx, starty, width, height;
height = LINES / 2 - 2;
width = COLS / 2;
starty = LINES / 2;
startx = 0;
warningWin = create_newwin(height, width, starty, startx);
mvwprintw(warningWin, 2, 2, "ATTENZIONE! E' avvenuto un errore . . . ");
word_wrap_print(warningWin, 4, 3, width - 5, string);
wrefresh(warningWin);
getch();
destroy_win(warningWin);
}
WINDOW *create_newwin(int height, int width, int starty, int startx) WINDOW *create_newwin(int height, int width, int starty, int startx)
{ WINDOW *local_win; { WINDOW *local_win;
@@ -128,17 +160,14 @@ WINDOW *create_newwin(int height, int width, int starty, int startx)
void destroy_win(WINDOW *local_win) void destroy_win(WINDOW *local_win)
{ {
wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' '); wborder(local_win, ':', ':', '.', '.', '+', '+', '+', '+');
wrefresh(local_win); wrefresh(local_win);
delwin(local_win); delwin(local_win);
} }
void print_menu(WINDOW *menu_win, int highlight) void print_menu(WINDOW *menu_win, int y, int x, int highlight)
{ {
int x, y, i; int i;
x = 3;
y = 3;
box(menu_win, 0, 0); box(menu_win, 0, 0);
for(i = 0; i < n_mainMenu; ++i) for(i = 0; i < n_mainMenu; ++i)
{ if(highlight == i + 1) /* High light the present choice */ { if(highlight == i + 1) /* High light the present choice */
@@ -153,10 +182,67 @@ void print_menu(WINDOW *menu_win, int highlight)
wrefresh(menu_win); wrefresh(menu_win);
} }
void word_wrap_print(WINDOW *win, int start_y, int start_x, int max_width, const char *str) {
int y = start_y;
int x = start_x;
int line_length = 0;
int word_length = 0;
const char *word_start = str;
while (*str) {
// Trova la prossima parola
if (*str != ' ' && *str != '\n' && *str != '\t') {
str++;
continue;
}
// Calcola lunghezza parola corrente
word_length = str - word_start;
// Gestione wrap
if (line_length + word_length > max_width) {
y++;
x = start_x;
line_length = 0;
}
// Stampa parola
for (int i = 0; i < word_length; i++) {
mvwaddch(win, y, x++, word_start[i]);
}
line_length += word_length;
// Gestione spazi
if (*str == ' ' || *str == '\t') {
if (line_length < max_width) {
mvwaddch(win, y, x++, ' ');
line_length++;
} else {
y++;
x = start_x;
line_length = 0;
}
} else if (*str == '\n') {
y++;
x = start_x;
line_length = 0;
}
word_start = ++str;
}
// Stampa ultima parola
word_length = strlen(word_start);
if (line_length + word_length > max_width) {
y++;
x = start_x;
}
mvwprintw(win, y, x, "%s", word_start);
}
int checkIfFileExists(){ int checkIfFileExists(){
return 0;
} }
void changeFile(){ void changeFile(){
@@ -165,5 +251,6 @@ void changeFile(){
int getCount(){ int getCount(){
return 0;
} }
BIN
View File
Binary file not shown.