From: Lukáš Jiřiště Date: Sun, 15 Dec 2024 15:07:52 +0000 (+0100) Subject: Group WINDOW* to a struct, add border X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=f2216e0959b81bc7b0cfd1fb9cc53c24f4c999dd;p=FET_sim.git Group WINDOW* to a struct, add border The structure makes manipulation of windows easier. --- diff --git a/inc/FET_sim.h b/inc/FET_sim.h index e8efc85..f4cc3af 100644 --- a/inc/FET_sim.h +++ b/inc/FET_sim.h @@ -95,6 +95,12 @@ typedef struct s_input t_arg argv[MAX_ARGS]; } t_input; +typedef struct s_windows +{ + WINDOW *command_win; + WINDOW *schematics_win; + WINDOW *border_win; +} t_windows; void add_node(t_vec *nodes, t_state set_state); void add_mosfet(t_vec *mosfets, t_type type); @@ -114,8 +120,8 @@ void update_nodes(t_vec *nodes); int should_open(t_type type, t_state state); int sim_step(t_vec *nodes, t_vec *mosfets); -void setup_terminal(WINDOW **command_win, WINDOW **schematics_win); -void clean_terminal(WINDOW *command_win, WINDOW *schematics_win); +void setup_terminal(t_windows *windows); +void clean_terminal(t_windows *windows); void print_start(WINDOW *command_win); void command_not_found(WINDOW *command_win, const char *input); void print_help(WINDOW *command_win, t_command c); diff --git a/src/main.c b/src/main.c index 146baeb..3e54974 100644 --- a/src/main.c +++ b/src/main.c @@ -242,29 +242,28 @@ int process_input(WINDOW *command_win, t_vec *nodes, t_vec *mosfets) return (res); } -void cleanup(t_vec *nodes, t_vec *mosfets, WINDOW *command_win, WINDOW *schematics_win) +void cleanup(t_vec *nodes, t_vec *mosfets, t_windows *windows) { update_nodes(NULL); ft_vec_free(nodes, free_node); ft_vec_free(mosfets, NULL); - clean_terminal(command_win, schematics_win); + clean_terminal(windows); return ; } int main(void) { - t_vec nodes; - t_vec mosfets; - WINDOW *command_win; - WINDOW *schematics_win; + t_vec nodes; + t_vec mosfets; + t_windows windows; ft_vec_init(&nodes, sizeof(t_node)); ft_vec_init(&mosfets, sizeof(t_mosfet)); - setup_terminal(&command_win, &schematics_win); - print_start(command_win); + setup_terminal(&windows); + print_start(windows.command_win); //if (argc > 1) // build_graph(argv[1], &nodes, &mosfets); - while (process_input(command_win, &nodes, &mosfets)); - cleanup(&nodes, &mosfets, command_win, schematics_win); + while (process_input(windows.command_win, &nodes, &mosfets)); + cleanup(&nodes, &mosfets, &windows); return (0); } diff --git a/src/terminal.c b/src/terminal.c index 4afea4d..14fe9c1 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -6,17 +6,20 @@ #define INPUT_BUFFER_SIZE 100 #define COMMAND_WIN_COLS 60 -void setup_terminal(WINDOW **command_win, WINDOW **schematics_win) +void setup_terminal(t_windows *windows) { initscr(); init_colors(); - *schematics_win = newwin(0, COLS - COMMAND_WIN_COLS, 0, 0); - *command_win = newwin(0, COMMAND_WIN_COLS, 0, COLS - COMMAND_WIN_COLS); - keypad(*command_win, TRUE); + windows->command_win = newwin(0, COMMAND_WIN_COLS, 0, COLS - COMMAND_WIN_COLS); + windows->schematics_win = newwin(0, COLS - COMMAND_WIN_COLS - 2, 0, 0); + windows->border_win = newwin(0, 1, 0, COLS - COMMAND_WIN_COLS - 1); + keypad(windows->command_win, TRUE); nonl(); cbreak(); echo(); - scrollok(*command_win, TRUE); + scrollok(windows->command_win, TRUE); + wborder(windows->border_win, ACS_VLINE, ACS_VLINE, ACS_VLINE, ACS_VLINE, ACS_VLINE, ACS_VLINE, ACS_VLINE, ACS_VLINE); + wrefresh(windows->border_win); return ; } @@ -62,10 +65,11 @@ int get_input(WINDOW *command_win, t_input *input) } -void clean_terminal(WINDOW *command_win, WINDOW *schematics_win) +void clean_terminal(t_windows *windows) { - delwin(schematics_win); - delwin(command_win); + delwin(windows->command_win); + delwin(windows->schematics_win); + delwin(windows->border_win); endwin(); return ; }