Refactor UART handling: update UART status management, improve dialog window dimensions, and enhance main menu display.
This commit is contained in:
@@ -11,14 +11,12 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
char *header = "Enter UART Address";
|
||||
char input[51] = {"\0"};
|
||||
|
||||
int win_height = 15;
|
||||
int win_height = 8;
|
||||
int win_width = 80;
|
||||
int start_y = (terminal_y - win_height) / 2;
|
||||
int start_x = (terminal_x - win_width) / 2;
|
||||
|
||||
start_color();
|
||||
init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
||||
init_pair(2, COLOR_WHITE, COLOR_RED);
|
||||
|
||||
WINDOW *uartwin = newwin(win_height, win_width, start_y, start_x);
|
||||
|
||||
@@ -26,8 +24,10 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
|
||||
box(uartwin, 0, 0);
|
||||
wattron(uartwin, COLOR_PAIR(1));
|
||||
wattron(uartwin, A_BOLD);
|
||||
mvwprintw(uartwin, 0, (win_width - strlen(header)) / 2, "%s", header);
|
||||
mvwprintw(uartwin, 3, (win_width - strlen(prompt)) / 2, "%s", prompt);
|
||||
wattroff(uartwin, A_BOLD);
|
||||
mvwprintw(uartwin, 2, (win_width - strlen(prompt)) / 2, "%s", prompt);
|
||||
wattroff(uartwin, COLOR_PAIR(1));
|
||||
wrefresh(uartwin);
|
||||
|
||||
@@ -46,9 +46,9 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
else
|
||||
wattron(uartwin, COLOR_PAIR(1));
|
||||
|
||||
mvwprintw(uartwin, 5, text_x, "[%50s]", input);
|
||||
mvwprintw(uartwin, 4, text_x, "[%50s]", input);
|
||||
if (!strcmp(input, "\0"))
|
||||
mvwprintw(uartwin, 5, text_x, "[__________________________________________________]");
|
||||
mvwprintw(uartwin, 4, text_x, "[__________________________________________________]");
|
||||
|
||||
if (highlight == 0)
|
||||
wattroff(uartwin, COLOR_PAIR(2));
|
||||
@@ -60,11 +60,15 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
wattron(uartwin, COLOR_PAIR(2));
|
||||
else
|
||||
wattron(uartwin, COLOR_PAIR(1));
|
||||
mvwprintw(uartwin, 7, button_x - 2, " %s ", "<Enter>");
|
||||
wattron(uartwin, A_BOLD);
|
||||
|
||||
mvwprintw(uartwin, 6, button_x - 2, " %s ", "<Enter>");
|
||||
if (highlight == 1)
|
||||
wattroff(uartwin, COLOR_PAIR(2));
|
||||
else
|
||||
wattroff(uartwin, COLOR_PAIR(1));
|
||||
wattroff(uartwin, A_BOLD);
|
||||
|
||||
wrefresh(uartwin);
|
||||
|
||||
flushinp();
|
||||
@@ -79,9 +83,9 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
{
|
||||
if (highlight == 0)
|
||||
{
|
||||
mvwprintw(uartwin, 5, (win_width - 52) / 2, "[__________________________________________________]");
|
||||
mvwprintw(uartwin, 4, (win_width - 52) / 2, "[__________________________________________________]");
|
||||
echo();
|
||||
wmove(uartwin, 5, ((win_width - 52) / 2) + 1);
|
||||
wmove(uartwin, 4, ((win_width - 52) / 2) + 1);
|
||||
curs_set(1);
|
||||
flushinp();
|
||||
wgetnstr(uartwin, input, 50);
|
||||
@@ -108,66 +112,81 @@ void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
|
||||
void mainMenu(list_t *person_list, int terminal_x, int terminal_y)
|
||||
{
|
||||
int win_height = 30;
|
||||
int win_width = 80;
|
||||
int win_height = 10;
|
||||
int win_width = 50;
|
||||
int start_y = (terminal_y - win_height) / 2;
|
||||
int start_x = (terminal_x - win_width) / 2;
|
||||
|
||||
char choices[6][30] = {"List all employees","Find employee","Edit database","Save","Save as...","Exit"};
|
||||
char choices[6][30] = {"List all employees", "Find employee", "Edit database", "Save", "Save as...", "Exit"};
|
||||
|
||||
char keboard_input;
|
||||
int highlight = 0;
|
||||
|
||||
start_color();
|
||||
init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
||||
init_pair(2, COLOR_WHITE, COLOR_RED);
|
||||
|
||||
WINDOW *uartwin = newwin(win_height, win_width, start_y, start_x);
|
||||
WINDOW *mainmenu = newwin(win_height, win_width, start_y, start_x);
|
||||
|
||||
wbkgd(uartwin, COLOR_PAIR(1));
|
||||
wbkgd(mainmenu, COLOR_PAIR(1));
|
||||
|
||||
box(uartwin, 0, 0);
|
||||
wattron(uartwin, COLOR_PAIR(1));
|
||||
|
||||
wattroff(uartwin, COLOR_PAIR(1));
|
||||
keypad(uartwin, true);
|
||||
box(mainmenu, 0, 0);
|
||||
wattron(mainmenu, COLOR_PAIR(1));
|
||||
wattron(mainmenu, A_BOLD);
|
||||
mvwprintw(mainmenu, 0, (win_width - strlen("Administration")) / 2, "%s", "Administration");
|
||||
wattroff(mainmenu, A_BOLD);
|
||||
wattroff(mainmenu, COLOR_PAIR(1));
|
||||
keypad(mainmenu, true);
|
||||
|
||||
int text_x = (win_width - 52) / 2;
|
||||
|
||||
wrefresh(uartwin);
|
||||
wrefresh(mainmenu);
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (i == highlight)
|
||||
wattron(mainmenu, COLOR_PAIR(2));
|
||||
else
|
||||
wattron(mainmenu, COLOR_PAIR(1));
|
||||
wattron(mainmenu, A_BOLD);
|
||||
mvwprintw(mainmenu, 2 + i, (win_width - strlen(choices[i])) / 2, "%s", choices[i]);
|
||||
wattroff(mainmenu, A_BOLD);
|
||||
|
||||
if (i == highlight)
|
||||
wattroff(mainmenu, COLOR_PAIR(2));
|
||||
else
|
||||
wattroff(mainmenu, COLOR_PAIR(1));
|
||||
}
|
||||
wrefresh(mainmenu);
|
||||
flushinp();
|
||||
keboard_input = wgetch(uartwin);
|
||||
keboard_input = wgetch(mainmenu);
|
||||
|
||||
if (keboard_input == '\t')
|
||||
{
|
||||
highlight = !highlight;
|
||||
if (highlight < 5)
|
||||
highlight++;
|
||||
else
|
||||
highlight = 0;
|
||||
}
|
||||
|
||||
else if (keboard_input == '\n')
|
||||
{
|
||||
if (highlight == 0)
|
||||
{
|
||||
|
||||
}
|
||||
else if (highlight == 1)
|
||||
switch (highlight)
|
||||
{
|
||||
|
||||
case 5:
|
||||
if (keboard_input == '\n')
|
||||
{
|
||||
wclear(uartwin);
|
||||
wrefresh(uartwin);
|
||||
wclear(mainmenu);
|
||||
wrefresh(mainmenu);
|
||||
touchwin(stdscr);
|
||||
refresh();
|
||||
delwin(uartwin);
|
||||
delwin(mainmenu);
|
||||
refresh();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user