Display price of sol in main menu
This commit is contained in:
parent
7c65367a71
commit
6fff2e7525
28
main.cpp
28
main.cpp
|
@ -36,16 +36,17 @@ double getConversionRate() {
|
||||||
return rate;
|
return rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayMenu(WINDOW *menu_win, int highlight, const std::string choices[], int n_choices) {
|
void displayMenu(WINDOW *menu_win, int highlight, const std::string choices[], int n_choices, double solRate) {
|
||||||
int x = 2, y = 2;
|
int x = 2, y = 2;
|
||||||
box(menu_win, 0, 0);
|
box(menu_win, 0, 0);
|
||||||
|
mvwprintw(menu_win, 1, 1, "1 SOL = $%.2f", solRate);
|
||||||
for(int i = 0; i < n_choices; ++i) {
|
for(int i = 0; i < n_choices; ++i) {
|
||||||
if(highlight == i + 1) {
|
if(highlight == i + 1) {
|
||||||
wattron(menu_win, A_REVERSE);
|
wattron(menu_win, A_REVERSE);
|
||||||
mvwprintw(menu_win, y, x, "%s", choices[i].c_str());
|
mvwprintw(menu_win, y + 1, x, "%s", choices[i].c_str());
|
||||||
wattroff(menu_win, A_REVERSE);
|
wattroff(menu_win, A_REVERSE);
|
||||||
} else
|
} else
|
||||||
mvwprintw(menu_win, y, x, "%s", choices[i].c_str());
|
mvwprintw(menu_win, y + 1, x, "%s", choices[i].c_str());
|
||||||
++y;
|
++y;
|
||||||
}
|
}
|
||||||
wrefresh(menu_win);
|
wrefresh(menu_win);
|
||||||
|
@ -73,21 +74,24 @@ int main() {
|
||||||
noecho();
|
noecho();
|
||||||
cbreak();
|
cbreak();
|
||||||
|
|
||||||
int highlight = 1;
|
|
||||||
int choice = 0;
|
|
||||||
int c;
|
|
||||||
|
|
||||||
start_color();
|
start_color();
|
||||||
init_pair(1, COLOR_CYAN, COLOR_BLACK);
|
init_pair(1, COLOR_CYAN, COLOR_BLACK);
|
||||||
|
|
||||||
|
double rate = getConversionRate();
|
||||||
|
|
||||||
WINDOW *menu_win = newwin(7, 60, 4, 4);
|
WINDOW *menu_win = newwin(7, 60, 4, 4);
|
||||||
keypad(menu_win, TRUE);
|
keypad(menu_win, TRUE);
|
||||||
mvprintw(0, 0, "Use arrow keys to go up and down, Press enter to select a choice");
|
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
const std::string choices[] = {"Convert SOL to USD", "Convert USD to SOL", "Exit"};
|
const std::string choices[] = {"Convert SOL to USD", "Convert USD to SOL", "Exit"};
|
||||||
int n_choices = sizeof(choices) / sizeof(std::string);
|
int n_choices = sizeof(choices) / sizeof(std::string);
|
||||||
displayMenu(menu_win, highlight, choices, n_choices);
|
|
||||||
|
int highlight = 1;
|
||||||
|
|
||||||
|
displayMenu(menu_win, highlight, choices, n_choices, rate);
|
||||||
|
|
||||||
|
int choice = 0;
|
||||||
|
int c;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
c = wgetch(menu_win);
|
c = wgetch(menu_win);
|
||||||
|
@ -112,7 +116,7 @@ int main() {
|
||||||
endwin();
|
endwin();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
double rate = getConversionRate();
|
rate = getConversionRate();
|
||||||
if (rate == 0.0) {
|
if (rate == 0.0) {
|
||||||
printw("Failed to fetch conversion rate. Please try again later.\n");
|
printw("Failed to fetch conversion rate. Please try again later.\n");
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,13 +125,13 @@ int main() {
|
||||||
printw("Press any key to return to the menu.");
|
printw("Press any key to return to the menu.");
|
||||||
getch();
|
getch();
|
||||||
clear();
|
clear();
|
||||||
displayMenu(menu_win, highlight, choices, n_choices);
|
displayMenu(menu_win, highlight, choices, n_choices, rate);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
displayMenu(menu_win, highlight, choices, n_choices);
|
displayMenu(menu_win, highlight, choices, n_choices, rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
endwin();
|
endwin();
|
||||||
|
|
Loading…
Reference in New Issue